QDesktopWidget Class▲
-
Header: QDesktopWidget
-
qmake: QT += widgets
-
Inherits: QWidget
-
Group: QDesktopWidget is part of advanced, desktop
This class is deprecated. We strongly advise against using it in new code.
Detailed Description▲
Systems with more than one graphics card and monitor can manage the physical screen space available either as multiple desktops, or as a large virtual desktop.
This class provides information about the user's desktop, such as its total size, number of screens, the geometry of each screen, and whether they are configured as separate desktops or a single virtual desktop.
Widgets provided by Qt use this class to place tooltips, menus and dialog boxes on the correct screen for their parent or application widgets. Applications can use this class to obtain information that can be used to save window positions, or to place child widgets and dialogs on one particular screen.
Obtaining a Desktop Widget▲
The QApplication::desktop() function is used to get an instance of QDesktopWidget.
The widget's screenGeometry() function provides information about the geometry of the available screens with. The number of screens available is returned by screenCount, and the screenCountChanged() signal is emitted when screens are added or removed. The screen number that a particular point or widget is located in is returned by screenNumber().
Screen Geometry▲
To obtain the dimensions of a particular screen, call the screenGeometry() function. On some desktop environments, not all of the screen is available for applications to use; for example, an application dock or menu bar may take up some space. Use the availableGeometry() function to obtain the available area for applications.
QDesktopWidget also inherits the QWidget properties, width() and height(), which specify the size of the desktop. However, for desktops with multiple screens, the size of the desktop is the union of all the screen sizes, so width() and height() should not be used for computing the size of a widget to be placed on one of the screens.
On systems that are configured to use the available screens as a single, large virtual desktop, the virtualDesktop property will be set to true. In this case, the widget's size is usually the size of the bounding rectangle of all the screens.
Use of the Primary Screen▲
For an application, the screen where the main widget resides is the primary screen. This is stored in the primaryScreen property. All windows opened in the context of the application should be constrained to the boundaries of the primary screen; for example, it would be inconvenient if a dialog box popped up on a different screen, or split over two screens.
In the illustration above, Application One's primary screen is screen 0, and App Two's primary screen is screen 1.
See Also▲
See also QApplication, QApplication::desktop()
Member Function Documentation▲
const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const▲
This is an overloaded function.
Returns the available geometry of the screen which contains widget.
See Also▲
See also screenGeometry()
const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const▲
This is an overloaded function.
Returns the geometry of the screen which contains widget.
int QDesktopWidget::screenNumber(const QWidget *widget = nullptr) const▲
Returns the index of the screen that contains the largest part of widget, or -1 if the widget not on a screen.
See Also▲
See also primaryScreen
Obsolete Members for QDesktopWidget▲
The following members of class QDesktopWidget are deprecated. We strongly advise against using them in new code.
Obsolete Property Documentation▲
[read-only] primaryScreen : const int▲
This property is deprecated. We strongly advise against using it in new code.
This property holds the index of the screen that is configured to be the primary screen on the system.
Use QGuiApplication::primaryScreen() instead.
Access functions:
-
int primaryScreen() const
Notifier signal:
-
void primaryScreenChanged()
[read-only, since 4.6] screenCount : const int▲
This property is deprecated. We strongly advise against using it in new code.
This property holds the number of screens currently available on the system.
Use QGuiApplication::screens() instead.
This property was introduced in Qt 4.6.
Access functions:
-
int screenCount() const
Notifier signal:
-
void screenCountChanged(int newCount)
[read-only] virtualDesktop : const bool▲
This property is deprecated. We strongly advise against using it in new code.
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.
Use QScreen::virtualSiblings() of primary screen instead.
Access functions:
-
bool isVirtualDesktop() const
Obsolete Member Function Documentation▲
const QRect QDesktopWidget::availableGeometry(int screen = -1) const▲
This function is deprecated. We strongly advise against using it in new code.
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 is -1.
Use QGuiApplication::screens() instead.
See Also▲
See also screenNumber(), screenGeometry(), QScreen::availableGeometry()
const QRect QDesktopWidget::availableGeometry(const QPoint &p) const▲
This function is deprecated. We strongly advise against using it in new code.
This is an overloaded function.
Returns the available geometry of the screen which contains p.
Use QGuiApplication::screenAt() instead.
See Also▲
See also screenGeometry()
int QDesktopWidget::numScreens() const▲
This function is deprecated. We strongly advise against using it in new code.
Returns the number of available screens.
Use QGuiApplication::screens() instead.
See Also▲
See also primaryScreen
[since 5.6] void QDesktopWidget::primaryScreenChanged()▲
This function is deprecated. We strongly advise against using it in new code.
This signal is emitted whenever the primary screen changes.
This doesn't mean the QDesktopWidget::primaryScreen index will necessarily be different, but now it will refer to the new primary screen.
Use QGuiApplication::primaryScreenChanged() instead.
Notifier signal for property primaryScreen.
This function was introduced in Qt 5.6.
See Also▲
See also primaryScreen, screenGeometry()
void QDesktopWidget::resized(int screen)▲
This function is deprecated. We strongly advise against using it in new code.
This signal is emitted when the size of screen changes.
Use QScreen::geometryChanged() instead.
QWidget *QDesktopWidget::screen(int screen = -1)▲
This function is deprecated. We strongly advise against using it in new code.
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.
Use QScreen instead.
See Also▲
See also primaryScreen, screenCount, virtualDesktop
[since 4.6] void QDesktopWidget::screenCountChanged(int newCount)▲
This function is deprecated. We strongly advise against using it in new code.
This signal is emitted when the number of screens changes to newCount.
Use QGuiApplication::screenAdded and QGuiApplication::screenRemoved() instead.
Notifier signal for property screenCount.
This function was introduced in Qt 4.6.
See Also▲
See also screenCount
const QRect QDesktopWidget::screenGeometry(int screen = -1) const▲
This function is deprecated. We strongly advise against using it in new code.
Returns the geometry of the screen with index screen. The default screen is used if screen is -1.
Use QGuiApplication::screens() instead.
See Also▲
See also screenNumber()
const QRect QDesktopWidget::screenGeometry(const QPoint &p) const▲
This function is deprecated. We strongly advise against using it in new code.
This is an overloaded function.
Returns the geometry of the screen which contains p.
Use QGuiApplication::screenAt() instead.
int QDesktopWidget::screenNumber(const QPoint &point) const▲
This function is deprecated. We strongly advise against using it in new code.
This is an overloaded function.
Returns the index of the screen that contains the point, or the screen which is the shortest distance from the point.
Use QGuiApplication::screenAt() instead.
See Also▲
See also primaryScreen
void QDesktopWidget::workAreaResized(int screen)▲
This function is deprecated. We strongly advise against using it in new code.
This signal is emitted when the work area available on screen changes.
Use QScreen::availableGeometryChanged() instead.