圖形

跨平颱應用程序可以使用 Qt 以顯示圖形元素。Qt 抽象瞭平颱底層圖形 API,以便開發者可以聚焦於應用程序代碼。

Qt RHI (渲染硬件接口) 將來自 Qt 應用程序的 3D 圖形調用,翻譯成目標平颱上的可用圖形 API。

支持的圖形 API:

  • OpenGL (第 2.1 版及更高版本)
  • OpenGL ES (第 2.0 版及更高版本)
  • Vulkan (第 1.0 版及更高版本)
  • Direct3D 11 (第 11.1 版及更高版本)
  • Direct3D 12 (第 12.0 版及更高版本)
  • Metal (第 1.2 版及更高版本)

Qt Quick 中的圖形

Qt Quick 應用程序使用 場景圖形 為渲染。場景圖形渲染器可以創建有效圖形調用並提高性能。場景圖形擁有可訪問 API,給予創建復雜且快速圖形的靈活性。

以下列錶的頁麵包含渲染 Qt Quick 應用程序的更多有關信息。

選取渲染路徑

Qt 盡可能使用目標平颱的圖形 API,不管怎樣,采用特定 API 設置 Qt 的渲染路徑是可能的。在許多情況下,選擇特定 API 可以提高性能,且允許開發者在具有特定圖形 API 的平颱上部署。拜訪 憑藉 Qt 渲染硬件接口進行渲染 頁麵關於如何設置渲染路徑在 QQuickWindow .

2D 圖形

Qt has multiple different APIs for drawing 2D graphics primitives. See the separate page about Qt 2D 圖形 for an overview of the possibilities here.

采用 Qt Quick 3D 的 3D 圖形

Qt Quick 3D 是提供高級 API (用於基於 Qt Quick 創建 3D 內容和 3D 用戶界麵) 的插件。它擴展瞭 Qt Quick 場景圖形 ,它使您可以在 2D Qt Quick 應用程序中實現 3D 內容。

著色器效果

The Qt Shader Tools 提供工具, QSB ,以將頂點和片段著色器翻譯成 Qt Quick 接口包。尤其, ShaderEffect QML 類型和 QSGMaterial 子類可以使用 QSB 的輸齣。 Qt Quick 3D 有它自己的框架,用於將著色器導入 3D 場景。

以下列錶包含著色器效果的有關信息。

采用 Qt GUI 的高級圖形

Qt GUI 提供高級窗口、描繪和排印係統。 QPainter 提供將嚮量圖形、文本及圖像繪製到不同錶麵的 API,或 QPaintDevice 實例,譬如 QImage , QOpenGLPaintDevice , QWidget ,和 QPrinter 。對於 Qt Widgets 用戶界麵,Qt 使用軟件渲染器。

以下列錶包含 Qt GUI 高級繪製 API 的有關信息。

采用 Qt GUI 的底層圖形

Qt GUI provides cross-platform enablers for managing OpenGL contexts and Vulkan instances. Applications that perform rendering directly with OpenGL, OpenGL ES, or Vulkan can use QOpenGLContext , QOpenGLFunctions , QVulkanInstance , QVulkanFunctions ,和 QVulkanDeviceFunctions to manage contexts, instances, and gain access to the OpenGL and Vulkan API functionsin a portable manner.

Qt GUI also offers the Qt Rendering Hardware Interface (RHI) family of APIs, such as QRhi and QShader , for applications that want to perform rendering using the portable, cross-platform 3D rendering infrastructure Qt itself uses to implement the Qt Quick scene graph and the Qt Quick 3D rendering engine. These classes are offered as "semi-public" APIs with a limited compatibility promise for the time being, similarly to the Qt Platform Abstraction classes. However, the QRhi classes come with full documentation. See the QRhi class to get started.

The Qt GUI module on its own allows targeting a QWindow or an offscreen buffer, such as a QRhiTexture ,采用 QRhi -based rendering. With user interfaces based on QWidget or QML (Qt Quick) working with a QWindow backed by a native platform is not always the most convenient way. This is why the Qt Widgets 模塊提供 QRhiWidget , whereas Qt Quick provides QQuickRhiItem . These base classes allow convenient creation of QWidget or QQuickItem subclasses, instances of which perform portable QRhi -based rendering into a texture that is then composited automatically with the Widgets or Qt Quick scene.

Qt OpenGL 模塊

The Qt OpenGL 模塊用於要求訪問 OpenGL 的應用程序。此模塊用於保持兼容 Qt 5 應用程序和 Qt GUI。若用戶界麵使用 QWidget , QOpenGLWidget 是可以添加 OpenGL 場景的小部件。

打印

Qt 支持直接打印到本地或網絡的實際打印機,及産生 PDF 輸齣。如何采用 Qt 進行打印的詳細描述在 Qt Print Support 頁麵。

圖像

Qt 支持圖像的方便讀取、寫入及操縱透過 QImage 類。此外,對於如何更細粒度控製圖像的加載或保存,可以使用 QImageReader and QImageWriter 類。為添加由 Qt 所提供的其它圖像格式的支持,可以創建圖像格式插件通過使用 QImageIOHandler and QImageIOPlugin .

讀寫圖像文件 頁麵,瞭解更多信息。