Creating a custom widget

It is time to actually get something onto the screen by painting on a widget. A widget is repainted as a result of receiving a paint event, which is handled by reimplementing the paintEvent() virtual method. This method accepts a pointer to the event object of the QPaintEvent type that contains various bits of information about the repaint request. Remember that you can only paint on the widget from within that widget's paintEvent() call.

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.