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.