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.

使用模块

使用 Qt 模块需要直接或通过其它依赖关系,链接模块库。一些构建工具为此有贡献支持,包括 CMake and qmake .

构建采用 CMake

使用 find_package() 命令去定位所需模块组件,在 Qt5 包:

find_package(Qt5 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget Qt5::Gui)
							

另请参阅 构建采用 CMake 概述。

采用 qmake 构建

若使用 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.

Vulkan 集成

Qt5.10 添加支持 Vulkan 。这要求存在 LunarG Vulkan SDK .

在 Windows,SDK 设置环境变量 VULKAN_SDK ,其会被检测到,通过 configure 脚本。

在 Android,NDK 的 API Level 24 添加了 Vulkan 头。

相关类:

更多信息,见 Hello Vulkan 小部件范例 Hello Vulkan 窗口范例 .

拖放

更多信息在 拖放

许可和归属

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

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

ANGLE Library, version chromium/3280

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

ANGLE: Array Bounds Clamper for WebKit

BSD 2 条款简化许可

ANGLE: Murmurhash

公共领域

ANGLE: Systeminfo

BSD 2 条款简化许可

ANGLE: trace_event

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

Adobe Glyph List For New Fonts, version 1.7

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

Anti-aliasing rasterizer from FreeType 2

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

Bitstream Vera Font, version 1.10

Bitstream Vera 字体许可

Cocoa Platform Plugin

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

DejaVu Fonts, version 2.37

Bitstream Vera 字体许可

Freetype 2 - Bitmap Distribution Format (BDF) support

MIT 许可

Freetype 2 - Portable Compiled Format (PCF) support

MIT 许可

Freetype 2 - zlib

zlib 许可

Freetype 2, version 2.9.1

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

HarfBuzz

MIT 许可

HarfBuzz-NG, version 1.7.4

MIT 许可

IAccessible2 IDL Specification, version 1.3.0

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

LibJPEG-turbo, version 2.0.3

独立 JPEG 组许可

LibPNG, version 1.6.37

libpng 许可和 libpng 许可 2

Native Style for Android

Apache 许可 2.0

OpenGL ES 2 Headers, version Revision 27673

MIT 许可

OpenGL Headers, version Revision 27684

MIT 许可

Pixman, version 0.17.12

MIT 许可

Smooth Scaling Algorithm

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

Vulkan API Registry, version 1.0.39

MIT 许可

WebGradients

MIT 许可

Wintab API

自定义许可

X Server helper

X11 许可和历史权限通知及免责声明

XCB

MIT 许可

sRGB color profile icc file

国际色彩联盟许可

参考