Qt GUI

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.

快速入门

要包括模块类定义,使用以下伪指令:

#include <QtGui>
							

若使用 qmake 去构建工程,默认包括 Qt GUI。要禁用 Qt GUI,添加以下行到 .pro 文件:

QT -= gui
							

应用程序窗口

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.

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 图形

Qt GUI 模块包含用于 2D 图形、图像、字体及高级排印的类。

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 描绘系统 and 光栅窗口范例 .

Qt 可以加载和保存图像,使用 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 读写图像文件

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 和 OpenGL ES 集成

QWindow supports rendering using OpenGL and OpenGL ES, 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, thus allowing cross-platform development of applications targeting mobile or embedded devices, and some classes that wrap native OpenGL functionality in a simpler Qt API:

Finally, in order to provide better support for the newer versions (3.0 and higher) of OpenGL, a versioned function wrapper mechanism is also available: The QOpenGLFunction_N_N family of classes expose all the functions in a given OpenGL version and profile, allowing easy development of desktop applications relying on modern, desktop-only OpenGL features.

更多信息,见 OpenGL 窗口范例 .

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 accelerated 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.

拖放

更多信息在 拖放

许可和归属

Qt GUI 在商业许可下是可用的来自 Qt 公司 。此外,它在自由软件许可下是可用的。从 Qt 5.4 起,这些自由软件许可是 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。

Furthermore, Qt GUI in Qt 5.9.9 may contain third-party modules under following permissive licenses:

ANGLE Library

BSD 3 条款新 (或修订) 许可

ANGLE: Array Bounds Clamper for WebKit

BSD 2 条款简化许可

ANGLE: Murmurhash

公共领域

ANGLE: Systeminfo

BSD 2 条款简化许可

ANGLE: trace_event

BSD 3 条款新 (或修订) 许可

Anti-aliasing rasterizer from FreeType 2

FreeType 工程许可或仅 GNU GPL (一般公共许可) 第 2.0 版

Cocoa 平台插件

BSD 3 条款新 (或修订) 许可

Freetype 2

FreeType 工程许可或仅 GNU GPL (一般公共许可) 第 2.0 版

Freetype 2 - Bitmap Distribution Format (BDF) support

MIT 许可

Freetype 2 - Portable Compiled Format (PCF) support

MIT 许可

Freetype 2 - zlib

zlib 许可

HarfBuzz

MIT 许可

HarfBuzz-NG

MIT 许可

IAccessible2 IDL Specification

BSD 3 条款新 (或修订) 许可

LibJPEG

独立 JPEG 组许可

LibPNG

libpng 许可和 libpng 许可 2

Native Style for Android

Apache 许可 2.0

OpenGL ES 2 Headers

MIT 许可

OpenGL Headers

MIT 许可

Pixman

MIT 许可

Smooth Scaling Algorithm

BSD 2 条款简化许可和 Imlib2 许可

Wintab API

公共领域

XCB

MIT 许可

xkbcommon

MIT Licenses (with no-advertisement clause)

参考