Qt has two main approaches to UI development: Qt Quick and Qt Widgets . They exist to support different types of user interfaces, and build on separate graphics engines that have been optimized for each of these types.
It is possible to combine code written in the OpenGL graphics API with both of these user interface types in Qt. This can be useful when the application has its own OpenGL-dependent code, or when it is integrating with a third-party OpenGL-based renderer.
The Qt OpenGL module contains convenience classes to make this type of integration easier and faster.
Qt Widgets is typically rendered by a highly optimized and accurate software rasterizer, and the final content reproduced on screen using a method appropriate for the platform where the application is running.
But it is also possible to combine Qt Widgets with OpenGL. The main entry point for this is the QOpenGLWidget class. This class can be used to enable OpenGL rendering for a certain part of the widget tree, and the classes in the Qt OpenGL module can be used to facilitate any application-side OpenGL code.
Qt Quick is optimized for hardware-accelerated rendering. By default, it will be built on the low-level graphics API most appropriate for the target platform.
For instance, it will default to
Direct3D
on Windows, whereas on macOS, it will default to
Metal
. But it is also possible to manually select OpenGL as the active graphics API on platforms where this is supported.
For more details on enabling OpenGL with Qt Quick ,见 scenegraph renderer documentation .
Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake .
使用
find_package()
command to locate the needed module component in the
Qt6
包:
find_package(Qt6 REQUIRED COMPONENTS OpenGL)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
更多细节,见 构建采用 CMake 概述。
To configure the module for building with qmake, add the module as a value of the
QT
variable in the project's .pro file:
QT += opengl
Qt OpenGL 的变化 lists important changes in the module API and functionality that were done for the Qt 6 series of Qt.
Qt OpenGL 模块在商业许可下是可用的来自 Qt 公司 . In addition, it is available under free software licenses: The GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。
OpenGL ® 是 Silicon (硅谷) 图形公司在美国及其它国家的商标。