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 to be GPU accelerated, you should turn your attention to Qt Quick (we will start working with it in Chapter 11, Introduction to Qt Quick). However, Qt Quick has its own limitations compared to Graphics View. This topic is elaborated in Nichols's article Should you still be using QGraphicsView?, available at https://blog.qt.io/blog/2017/01/19/should-you-be-using-qgraphicsview/. Alternatively, you can access the full power of OpenGL directly using its API and helpful Qt utilities. We will describe this approach in Chapter 9, OpenGL and Vulkan in Qt applications.