- Qt 6.7
- Qt OpenGL
- Qt 6.7.2 Reference Documentation

# Qt OpenGL

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 OpenGL and Qt Widgets

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 OpenGL and Qt Quick

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, see scenegraph renderer documentation.

## Using the Module

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.

### Building with CMake

Use the `find_package()` command to locate the needed module component in the `Qt6` package:

     find_package(Qt6 REQUIRED COMPONENTS OpenGL)
     target_link_libraries(mytarget PRIVATE Qt6::OpenGL)

For more details, see the Build with CMake overview.

### Building with qmake

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

## Examples

- Qt OpenGL Examples

## Reference

- C++ Classes

## Module Evolution

Changes to Qt OpenGL lists important changes in the module API and functionality that were done for the Qt 6 series of Qt.

## Licenses and Trademarks

The Qt OpenGL module is available under commercial licenses from The Qt Company. In addition, it is available under free software licenses: The GNU Lesser General Public License, version 3, or the GNU General Public License, version 2. See Qt Licensing for further details.

OpenGL® is a trademark of Silicon Graphics, Inc. in the United States and other countries.