The Qt GUI module provides classes for windowing system integration, event handling, OpenGL and OpenGL ES integration, 2D graphics, basic imaging, fonts and text. These classes are used internally by Qt's user interface technologies and can also be used directly, for instance to write applications using low-level OpenGL ES graphics APIs.

For application developers writing user interfaces, Qt provides higher level API's, like Qt Quick, that are much more suitable than the enablers found in the Qt GUI module.

Getting started

To include the definitions of the module's classes, use the following directive:

#include <QtGui>

If you use qmake to build your projects, Qt GUI is included by default. To disable Qt GUI, add the following line to your .pro file:

QT -= gui

Application Windows

The most important classes in the Qt GUI module are QGuiApplication and QWindow. A Qt application that wants to show content on screen, will need to make use of these. QGuiApplication contains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application's initialization and finalization.

The QWindow class represents a window in the underlying windowing system. It provides a number of virtual functions to handle events (QEvent) from the windowing system, such as touch-input, exposure, focus, key strokes and geometry changes.

2D Graphics

The Qt GUI module contains classes for 2D graphics, imaging, fonts and advanced typography.

A QWindow created with the surface type QSurface::RasterSurface can be used in combination with QBackingStore and QPainter, Qt's highly optimized 2D vector graphics API. QPainter supports drawing lines, polygons, vector paths, images and text. For more information, see Paint System and Raster Window Example.

Qt can load and save images using the QImage and QPixmap classes. By default, Qt supports the most common image formats including JPEG and PNG among others. Users can add support for additional formats via the QImageIOPlugin class. For more information, see Reading and Writing Image Files

Typography in Qt is done with QTextDocument which uses the QPainter API in combination with Qt's font classes, primarily QFont. Applications that prefer more low-level APIs to text and font handling, classes like QRawFont and QGlyphRun can be used.

OpenGL and OpenGL ES integration

QWindow supports rendering using desktop OpenGL, OpenGL ES 1.1 and OpenGL ES 2.0, depending on what the platform supports. OpenGL rendering is enabled by setting the QWindow's surface type to QSurface::OpenGLSurface, choosing the format attributes with QSurfaceFormat, and then creating a QOpenGLContext to manage the native OpenGL context. In addition, Qt has QOpenGLPaintDevice, which enables the use of OpenGL accelerated QPainter rendering, as well as convenience classes that simplify the writing of OpenGL code and hides the complexities of extension handling and the differences between OpenGL ES 2 and desktop OpenGL. The convenience classes include QOpenGLFunctions that lets an application use all the OpenGL ES 2 functions on desktop OpenGL without having to manually resolve the OpenGL function pointers and some classes that wrap native OpenGL resources in a simpler Qt API: QOpenGLBuffer, QOpenGLFramebufferObject, and QOpenGLShaderProgram.

For more information, see the OpenGL Window Example.

The Qt GUI module also contains a few math classes to aid with the most common mathmatical operations related to 3D graphics. These classes include QMatrix4x4, QVector4D and QQuaternion

A QWindow created with the QSurface::OpenGLSurface can be used in combination with QPainter and QOpenGLPaintDevice to have OpenGL hardware accellerated 2D graphics, by sacrificing some of the visual quality.

Qt GUI prior to Qt 5.0

Prior to Qt 5.0, the Qt GUI module was the monolithic container for all things relating to graphical user interfaces in Qt, and included the Qt widget set, the item views, the graphics view framework and also printing. Starting Qt 5, these classes have been moved to the Qt Widgets module. Printing has been moved to the Qt Print Support module. Please note that these modules can be excluded from a Qt installation.

Qt GUI now contains only a small set of enablers, which are generally useful for all graphical applications.

Drag and Drop

More info in Drag and Drop