I have a widget class subclass of QMainWindow, and it has a central widget(QWidget), and in the overriden paintEvent function, can I create an instance of QPainter on this central widget? Code like:
void MyMainWindow::paintEvent(QEvent *event)
{
QPainter painter(_theCentralWidget);
//drawing...
return QMainWindow::paintEvent(event);
}
I don't want to create a new c++ class subclass of QWidget and override its paintEvent function and then replace the original central widget with this new one... (I did like above but an error occured saying the painter is not active...)
Well. If you really, really, really don't want to sub-class the central widget, you can install a event filter to it and handle the paint event for it.
http://qt-project.org/doc/qt-4.8/qobject.html#installEventFilter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With