QDesktopWidget 类

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 )

额外继承成员

详细描述

QDesktopWidget 类提供对多头系统屏幕信息的访问。

具有多个图形卡和显示器的系统,可以管理作为多个桌面或大型虚拟桌面的可用物理屏幕空间。

此类提供有关用户桌面的信息,如总尺寸、屏幕数、每个屏幕的几何体及把它们配置成单独桌面或单个虚拟桌面。

由 Qt 提供的 Widget 使用此类把工具提示、菜单及对话框放置在其父级 (或应用程序 Widget) 的正确屏幕上。应用程序可以使用此类,以获得可用于保存窗口位置的信息,或在一特定屏幕上放置子级 Widget 和对话框。

获得桌面 Widget

QApplication::desktop () function is used to get an instance of QDesktopWidget .

Widget 的 screenGeometry () 函数,提供有关可用屏幕几何体的信息。返回可用屏幕数,通过 screenCount ,和 screenCountChanged () 信号被发射,当屏幕被添加或移除时。返回特定点或 Widget 所在的屏幕号,通过 screenNumber ().

屏幕几何体

要获得特定屏幕的尺度,调用 screenGeometry () 函数。在某些桌面环境,并非所有屏幕都可供应用程序使用;例如,应用程序 Dock 停靠 (或菜单栏) 可能占用一些空间。使用 availableGeometry () 函数,以获得应用程序的可用区域。

QDesktopWidget also inherits the QWidget 特性, width () 和 height () 指定桌面尺寸。但是,对于具有多个屏幕的桌面,桌面尺寸是所有屏幕大小的 Union (并集),因此 width () 和 height () 应该 not 用于计算,要被放置在某一屏幕上的 Widget 尺寸。

在将可用屏幕配置成单个大型虚拟桌面的系统中, virtualDesktop 特性会被设为 true。在这种情况下,Widget 的尺寸通常是所有屏幕的边界矩形尺寸。

首要屏幕的使用

对于应用程序,主 Widget 所在的屏幕是首要屏幕。这被存储在 primaryScreen 特性。打开于应用程序上下文的所有窗口,都应该被约束到首要屏幕边界;例如:它会很不方便,若对话框在不同屏幕中弹出,或分割于 2 屏幕上。

Managing Multiple Screens

上图中,Application One 的首要屏幕是 screen 0,App Two 的首要屏幕是 screen 1。

另请参阅 QApplication and QApplication::desktop ().

特性文档编制

primaryScreen : const int

This property holds the index of the screen that is configured to be the primary screen on the system.

访问函数:

int primaryScreen () const

通知程序信号:

void primaryScreenChanged ()

screenCount : const int

This property holds the number of screens currently available on the system.

该特性在 Qt 4.6 引入。

访问函数:

int screenCount () const

通知程序信号:

void screenCountChanged (int newCount )

virtualDesktop : const bool

if the system manages the available screens in a virtual desktop.

For virtual desktops, screen () will always return the same widget. The size of the virtual desktop is the size of this desktop widget.

访问函数:

bool isVirtualDesktop () const

成员函数文档编制

const QRect QDesktopWidget:: availableGeometry ( int screen = -1) 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 ().

const QRect QDesktopWidget:: availableGeometry (const QWidget * widget ) const

这是重载函数。

返回屏幕的可用几何体,其包含 widget .

另请参阅 screenGeometry ().

const QRect QDesktopWidget:: availableGeometry (const QPoint & p ) const

这是重载函数。

返回屏幕的可用几何体,其包含 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 改变。

QWidget *QDesktopWidget:: screen ( int screen = -1)

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 .

const QRect QDesktopWidget:: screenGeometry ( int screen = -1) const

Returns the geometry of the screen with index screen . The default screen is used if screen 为 -1。

另请参阅 screenNumber ().

const QRect QDesktopWidget:: screenGeometry (const QWidget * widget ) const

这是重载函数。

返回屏幕的几何体,其包含 widget .

const QRect QDesktopWidget:: screenGeometry (const QPoint & p ) const

这是重载函数。

返回屏幕的几何体,其包含 p .

int QDesktopWidget:: screenNumber (const QWidget * widget = Q_NULLPTR) const

返回屏幕的索引,包含最大部分的 widget ,或 -1 若 Widget 不在屏幕上。

另请参阅 primaryScreen .

int QDesktopWidget:: screenNumber (const QPoint & point ) const

这是重载函数。

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 改变。