What just happened?

Our new project is so simple that all its code is located in the main() function. Let's examine the code. First, we create a QApplication object, as in any Qt Widgets project. Next, we create a scene object and three instances of different item classes. The constructor of each item class accepts an argument that defines the content of the item:

  • The QGraphicsRectItem constructor receives a QRectF object that contains the coordinates of the rectangle
  • The QGraphicsEllipseItem constructor, similarly, receives a QRectF object that defines the bounding rectangle of the circle
  • The QGraphicsSimpleTextItem constructor receives the text to display
QRectF is basically a helpful struct with four fields that allow us to specify four ...

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.