O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom items

As we already saw, Graphics View provides a lot of useful functionality that covers most typical use cases. However, the real power of Qt is its extensibility, and Graphics View allows us to create custom subclasses of QGraphicsItem to implement items that are tailored for your application. You may want to implement a custom item class when you need to do the following:

  • Paint something that is not possible or difficult to do with standard item classes
  • Implement some logic related to the item, for example, add your own methods
  • Handle events in individual items

In our next small project, we will create an item that can draw a graph of the sine function sin(x) and implement some event handling.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required