OpenGL in the Graphics View

As a last optimization, you can take advantage of OpenGL. Instead of using the default viewport based on QWidget, advise Graphics View to use an OpenGL widget:

QGraphicsView view;
view.setViewport(new QOpenGLWidget()); 

This usually improves the rendering performance. However, Graphics View wasn't designed for GPUs and can't use them effectively. There are ways to improve the situation, but that goes beyond the topic and scope of this chapter. You can find more information about OpenGL and Graphics View in the Boxes Qt example as well as in Rødal's article "Accelerate your Widgets with OpenGL", which can be found online at https://doc.qt.io/archives/qq/qq26-openglcanvas.html.

If you want to use a framework designed ...

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.