Qt Widgets

The Qt Widgets 模塊 提供瞭一套創建經典桌麵風格用戶界麵的 UI 元素。請參閱 用戶界麵 概述,瞭解使用小部件的更多信息。

小部件

Widgets 是在 Qt 中創建用戶界麵的首要元素。 小部件 可以顯示數據和狀態信息,接收用戶輸入,及為應被分組在一起的其它 Widget 提供容器。未嵌入到父級 Widget 中的 Widget,稱為 window .

A parent widget containing various child widgets.

The QWidget 類提供渲染到屏幕及處理用戶輸入事件的基本功能。Qt 提供的所有 UI 元素是子類化的 QWidget ,或被用於連接 QWidget 子類。創建自定義 Widget 的完成,是通過子類化 QWidget 或適當子類並重實現虛擬事件處理程序。

樣式

樣式 代錶 Widget 繪製,並封裝 GUI 的外觀和感覺。Qt 的內置 Widget 使用 QStyle 類來履行其幾乎所有繪製,確保看起來準確像等效本機 Widget。

Qt 樣式錶 是允許定製 Widget 外觀的強大機製,除瞭可能已有的,通過子類化 QStyle .

布局

布局 是在容器中自動排列子級 Widget 的優雅 靈活方式。每個 Widget 嚮布局報告其尺寸要求透過 sizeHint and sizePolicy 特性,且布局會相應地分配可用空間。

Qt Designer 是交互創建和在布局中排列 Widget 的強大工具。

模型/視圖類

The 模型/視圖 體係結構提供嚮用戶呈現數據的方式的管理類。使用列錶和錶格驅動數據的應用程序,被結構化為使用模型、視圖及委托分離數據和視圖。

圖形視圖

The 圖形視圖框架 用於管理和與大量定製 2D 圖形項並與之交互,用於可視化這些項的視圖 Widget (支持縮放和鏇轉)。

使用模塊

Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake .

構建采用 CMake

使用 find_package() command to locate the needed module component in the Qt6 包:

find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
					

更多細節,見 構建采用 CMake 概述。

采用 qmake 構建

To configure the module for building with qmake, add the module as a value of the QT variable in the project's .pro file:

QT += widgets
					

文章和指南

範例

API 參考

Module Evolution

Qt Widgets 的變化 lists important changes in the module API and functionality that were done for the Qt 6 series of Qt.

許可

Qt Widget 模塊在商業許可下是可用的來自 Qt 公司 . In addition, it is available under free software licenses: The GNU LGPL (次一般公共許可) 第 3 版 ,或 GNU GPL (一般公共許可) 第 2 版 。見 Qt 許可 進一步瞭解細節。