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 but can also be used directly, for example to write applications using low-level OpenGL ES graphics APIs.

对于编写用户界面的应用程序开发者而言,Qt 提供更高级 API,像 Qt Quick,比 Qt GUI 模块中找到的使能器更合适。

应用程序窗口

Qt GUI 模块最重要的类是 QGuiApplication and QWindow 。Qt 应用程序想要在屏幕上展示内容,就必须使用这些。 QGuiApplication 包含主事件循环,来自窗口系统和其它源的所有事件都会被处理和分派。它还处理应用程序的初始化及定稿。

The QWindow 类表示在底层窗口系统中的窗口。它提供许多虚函数以处理事件 ( QEvent ) 来自窗口系统,譬如:触摸输入、暴露、聚焦、击键及几何体变化。

2D 图形

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

A QWindow 的创建采用表面类型 QSurface::RasterSurface 可以用于组合 QBackingStore and QPainter ,Qt 高度优化的 2D 向量图形 API。 QPainter supports drawing lines, polygons, vector paths, images, and text. For more information, see 描绘系统 and 光栅窗口范例 .

Qt 可以加载和保存图像,使用 QImage and QPixmap 类。默认情况下,Qt 支持最常见的图像格式,包括 JPEG 和 PNG 等。用户可以添加支持其它格式凭借 QImageIOPlugin 类。更多信息,见 读取和写入图像文件 .

Qt 中的排印是采用 QTextDocument ,使用 QPainter API 组合 Qt 的字体类,首要是 QFont 。偏好更低级 API 而不是文本和字体处理的应用程序,可以使用的的类像 QRawFont and QGlyphRun .

OpenGL 和 OpenGL ES 集成

QWindow 支持使用 OpenGL 和 OpenGL ES 进行渲染,取决于平台支持哪种。OpenGL 渲染的启用是通过设置 QWindow 的表面类型为 QSurface::OpenGLSurface ,选取格式属性采用 QSurfaceFormat ,然后创建 QOpenGLContext 以管理本机 OpenGL 上下文。此外,Qt 拥有 QOpenGLPaintDevice ,启用使用 OpenGL 加速 QPainter 渲染,还有方便类以简化 OpenGL 代码的编写,隐藏扩展处理的复杂性及 OpenGL ES 2 和桌面 OpenGL 之间的差异。方便类包括 QOpenGLFunctions that lets an application use all the OpenGL ES 2 functions on desktop OpenGL without having to manually resolve the OpenGL function pointers. This enables cross-platform development of applications targeting mobile or embedded devices, and provides classes that wrap native OpenGL functionality in a simpler Qt API:

最后,为更好地支持 OpenGL 较新版本 (3.0 及更高版本),版本化函数包裹器机制也可用:QOpenGLFunction_N_N 系列类暴露 OpenGL 版本和配置文件给定的所有函数,允许轻松开发依赖现代、仅限桌面 OpenGL 特征的桌面应用程序。

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

Qt GUI 模块还包含一些数学类,以辅助 3D 图形相关的最常见数学运算。这些类包括 QMatrix4x4 , QVector4D ,和 QQuaternion .

A QWindow 的创建采用 QSurface::OpenGLSurface 可以用于组合 QPainter and QOpenGLPaintDevice to have OpenGL hardware-accelerated 2D graphics by sacrificing some of the visual quality.

Vulkan 集成

Qt GUI 支持 Vulkan API。Qt 应用程序要求存在 LunarG Vulkan SDK .

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

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

相关类:

更多信息,见 Hello Vulkan 小部件范例 Hello Vulkan Triangle Example .

拖放

Qt GUI 包括对拖放的支持。 拖放 概述有更多信息。