Wayee
Wayee

Reputation: 449

Benefits of using QOpenGLWidget over normal QWidget

Since Qt 5.4 version, the QOpenGLWidget was introduced to enable the OpenGL rendering capabilities.

Apart of calling OpenGL APIs, QOpenGLWidget can also be used as a normal QWidget, in which QPainter is used.

So I'm wondering, if I don't plan to directly call any OpenGL API to render my widget, but only QPainter APIs, is there still any (performance perhaps) benefits of using QOpenGLWidget instead of QWidget?

Upvotes: 3

Views: 1684

Answers (1)

QOpenGLWidget, when directly painted on using QPainter, does all the painting using OpenGL - that's one of its two main purposes. Using QPainter on a QOpenGLWidget has Qt doing the legwork of translating the painter API into GL state setup and draw calls. If you have some OpenGL background and use a debug build of Qt, you can trace into the source and see how Qt translates your calls, so that you can issue your painter calls in a way that efficiently maps to OpenGL. State changes are expensive, so make sure you batch the operations that use the same pen/brush etc. The painting is done by the QOpenGL2PaintEngineEx.

Upvotes: 4

Related Questions