May 2019
Intermediate to advanced
542 pages
13h 37m
English
The QWidget class, just like QImage, is a subclass of QPaintDevice; as such, we can use a QPainter object to draw directly onto the widget. When a widget gets a request to redraw itself (similar to how we issued our call to update()), it calls its paintEvent() method. We can override this method with our own drawing commands to define a custom look for our widget.
Let's start the method as follows:
def paintEvent(self, paint_event): painter = qtg.QPainter(self)
paintEvent() will be called with one argument, a QPaintEvent object. This object contains information about the event that requested the repaint – most notably, the region and rectangle that needs to be redrawn. For a complex widget, we can use this information ...
Read now
Unlock full access