Creating custom widgets
Painting with a custom widget is at its heart no different than offscreen painting; all you need is a widget subclass and a painter pointing to the widget, and you're all set. Yet, how do you know when paint?
Qt's QWidget class defines an interface used by the rendering system to pass events to your widget: Qt defines the QEvent class to encapsulate the data about an event, and the QWidget class defines an interface that Qt's rendering system uses to pass events to your widget for processing. Qt uses this event system not just to indicate things like mouse movements and keyboard input, but also for requests to paint the screen as well.
Let's look at painting first. QWidget defines the paintEvent method, which Qt's rendering ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access