The QDesktopWidget 類提供對多頭係統屏幕信息的訪問。 更多...
| 頭: | #include <QDesktopWidget> |
| qmake: | QT += widgets |
| 繼承: | QWidget |
| const QRect | availableGeometry (int screen = -1) const |
| const QRect | availableGeometry (const QWidget * widget ) const |
| const QRect | availableGeometry (const QPoint & p ) const |
| bool | isVirtualDesktop () const |
| int | primaryScreen () const |
| QWidget * | screen (int screen = -1) |
| int | screenCount () const |
| const QRect | screenGeometry (int screen = -1) const |
| const QRect | screenGeometry (const QWidget * widget ) const |
| const QRect | screenGeometry (const QPoint & p ) const |
| int | screenNumber (const QWidget * widget = Q_NULLPTR) const |
| int | screenNumber (const QPoint & point ) const |
| void | primaryScreenChanged () |
| void | resized (int screen ) |
| void | screenCountChanged (int newCount ) |
| void | workAreaResized (int screen ) |
| virtual void | resizeEvent (QResizeEvent * event ) |
The QDesktopWidget 類提供對多頭係統屏幕信息的訪問。
具有多個圖形卡和顯示器的係統,可以管理作為多個桌麵或大型虛擬桌麵的可用物理屏幕空間。
此類提供有關用戶桌麵的信息,如總尺寸、屏幕數、每個屏幕的幾何體及把它們配置成單獨桌麵或單個虛擬桌麵。
由 Qt 提供的 Widget 使用此類把工具提示、菜單及對話框放置在其父級 (或應用程序 Widget) 的正確屏幕上。應用程序可以使用此類,以獲得可用於保存窗口位置的信息,或在一特定屏幕上放置子級 Widget 和對話框。
The QApplication::desktop () 函數用於獲取實例化的 QDesktopWidget .
Widget 的 screenGeometry () 函數,提供有關可用屏幕幾何體的信息。返迴可用屏幕數,通過 screenCount ,和 screenCountChanged () 信號被發射,當屏幕被添加或移除時。返迴特定點或 Widget 所在的屏幕號,通過 screenNumber ().
要獲得特定屏幕的尺度,調用 screenGeometry () 函數。在某些桌麵環境,並非所有屏幕都可供應用程序使用;例如,應用程序 Dock 停靠 (或菜單欄) 可能占用一些空間。使用 availableGeometry () 函數,以獲得應用程序的可用區域。
QDesktopWidget 還繼承瞭 QWidget 特性, width () 和 height () 指定桌麵尺寸。但是,對於具有多個屏幕的桌麵,桌麵尺寸是所有屏幕大小的 Union (並集),因此 width () 和 height () 應該 not 用於計算,要被放置在某一屏幕上的 Widget 尺寸。
在將可用屏幕配置成單個大型虛擬桌麵的係統中, virtualDesktop 特性會被設為 true。在這種情況下,Widget 的尺寸通常是所有屏幕的邊界矩形尺寸。
對於應用程序,主 Widget 所在的屏幕是首要屏幕。這被存儲在 primaryScreen 特性。打開於應用程序上下文的所有窗口,都應該被約束到首要屏幕邊界;例如:它會很不方便,若對話框在不同屏幕中彈齣,或分割於 2 屏幕上。
在以上插圖中,Application One 的首要屏幕是 screen 0,而 App Two 的首要屏幕是 screen 1。
另請參閱 QApplication and QApplication::desktop ().
This property holds the index of the screen that is configured to be the primary screen on the system.
訪問函數:
| int | primaryScreen () const |
通知程序信號:
| void | primaryScreenChanged () |
This property holds the number of screens currently available on the system.
該特性在 Qt 4.6 引入。
訪問函數:
| int | screenCount () const |
通知程序信號:
| void | screenCountChanged (int newCount ) |
if the system manages the available screens in a virtual desktop.
對於虛擬桌麵, screen () 將始終返迴相同 Widget。虛擬桌麵的大小就是此桌麵 Widget 的大小。
訪問函數:
| bool | isVirtualDesktop () const |
Returns the available geometry of the screen with index screen . What is available will be subrect of screenGeometry () based on what the platform decides is available (for example excludes the dock and menu bar on macOS, or the task bar on Windows). The default screen is used if screen 為 -1。
另請參閱 screenNumber () 和 screenGeometry ().
這是重載函數。
返迴屏幕的可用幾何體,其包含 widget .
另請參閱 screenGeometry ().
這是重載函數。
返迴屏幕的可用幾何體,其包含 p .
另請參閱 screenGeometry ().
[signal]
void
QDesktopWidget::
primaryScreenChanged
()
此信號被發射每當首要屏幕改變時。
注意: 這並不意味著 QDesktopWidget::primaryScreen 索引必然不同,但現在它會引用新的首要屏幕。
該函數在 Qt 5.6 引入。
注意: 通知程序信號對於特性 primaryScreen .
另請參閱 primaryScreen and screenGeometry ().
[virtual protected]
void
QDesktopWidget::
resizeEvent
(
QResizeEvent
*
event
)
重實現自 QWidget::resizeEvent ().
[signal]
void
QDesktopWidget::
resized
(
int
screen
)
此信號被發射當尺寸對於 screen 改變。
Returns a widget that represents the screen with index screen (a value of -1 means the default screen).
If the system uses a virtual desktop, the returned widget will have the geometry of the entire virtual desktop; i.e., bounding every screen .
另請參閱 primaryScreen , screenCount ,和 virtualDesktop .
[signal]
void
QDesktopWidget::
screenCountChanged
(
int
newCount
)
此信號被發射當屏幕數改變成 newCount .
該函數在 Qt 4.6 引入。
注意: 通知程序信號對於特性 screenCount .
另請參閱 screenCount .
Returns the geometry of the screen with index screen . The default screen is used if screen 為 -1。
另請參閱 screenNumber ().
這是重載函數。
返迴屏幕的幾何體,其包含 widget .
這是重載函數。
返迴屏幕的幾何體,其包含 p .
返迴屏幕的索引,包含最大部分的 widget ,或 -1 若 Widget 不在屏幕上。
另請參閱 primaryScreen .
這是重載函數。
Returns the index of the screen that contains the point , or the screen which is the shortest distance from the point .
另請參閱 primaryScreen .
[signal]
void
QDesktopWidget::
workAreaResized
(
int
screen
)
此信號發射,當工作區域可用於 screen 改變。