Qt GUI Overview

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.

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

应用程序窗口

Qt GUI 模块最重要的类是 QGuiApplication and QWindow . A Qt application that wants to show content on screen has to use these. QGuiApplication 包含主事件循环,来自窗口系统和其它源的所有事件都会被处理和分派。它还处理应用程序的初始化及定稿。

The QWindow 类表示在底层窗口系统中的窗口。它提供许多虚函数以处理事件 ( QEvent ) from the windowing system, such as touch-input, exposure, focus, key strokes, and geometry changes.

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 . Applications that prefer more low-level APIs to text and font handling can use classes like 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:

Finally, 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 that rely on modern, desktop-only OpenGL features.

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

The Qt GUI module also contains a few math classes to aid with the most common mathematical operations related to 3D graphics. These classes include 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 has support for the Vulkan API. Qt applications require the presence of the LunarG Vulkan SDK .

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

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

相关类:

更多信息,见 Hello Vulkan 小部件范例 Hello Vulkan 三角形范例 .

拖放

Qt GUI includes support for drag and drop. The 拖放 overview has more information.