Hi!
When I use QPainter. Should I use the QPaintEvent with QPainter?
thanks.
Printable View
Hi!
When I use QPainter. Should I use the QPaintEvent with QPainter?
thanks.
When you want to paint something on a paint device:Quote:
When I use QPainter
QPainter can be used on images, printers and widgets (and few other things derived from QPaintDevice).Code:
painter.drawLine(0,0,image.width(),image.height()); // draw a diagonal line on an image
QPaintEvent is an event - it is sent to a widget that needs to update itself. It contains some parameters related to the area being repainted;
Typically you reimplement a "paintEvent" protected method in a class derived from QWidget:
When it comes to QWidgets, QPainter can be used only inside of paintEvent() method.Code:
Q_OBJECT protected: //... now you can draw something on current widget } };
QPainter is an object used to draw stuff on various paint devices (not necessarily widgets), whereas QPaintEvent is an event related to rendering on QWidgets and Qt event system.Quote:
The difference between QPinter and QPaintEvent