Qt OpenGL

Warning: This module should not be used anymore for new code. Please use the corresponding OpenGL classes in Qt GUI.

Introduction

OpenGL is a standard API for rendering 3D graphics. OpenGL only deals with 3D rendering and provides little or no support for GUI programming issues. The user interface for an OpenGL application must be created with another toolkit, such as Cocoa on the macOS platform, Microsoft Foundation Classes (MFC) under Windows, or Qt on both platforms.

The Qt OpenGL module makes it easy to use OpenGL in Qt applications. It provides an OpenGL widget class that can be used just like any other Qt widget, except that it opens an OpenGL display buffer where you can use the OpenGL API to render the contents.

The Qt OpenGL module is implemented as a platform-independent Qt/C++ wrapper around the platform-dependent GLX (version 1.3 or later), WGL, or AGL C APIs. Although the basic functionality provided is very similar to Mark Kilgard's GLUT library, applications using the Qt OpenGL module can take advantage of the whole Qt API for non-OpenGL-specific GUI functionality.

The Qt OpenGL C++ Classes page gives an overview over the available classes in this module.

Using the Module

Using a Qt module 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 components in the Qt5 package:

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

See also 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

Module Evolution

Porting to Qt 6 - 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.