返回介绍

QDesktopWidget Class

发布于 2019-10-04 14:59:24 字数 4682 浏览 956 评论 0 收藏 0

The QDesktopWidget class provides access to screen information on multi-head systems. More...

#include <qdesktopwidget.h>

Inherits QWidget.

List of all member functions.

Public Members

  • QDesktopWidget ()
  • ~QDesktopWidget ()
  • bool isVirtualDesktop () const
  • int numScreens () const
  • int primaryScreen () const
  • int screenNumber ( QWidget*widget = 0 ) const
  • int screenNumber ( constQPoint&point ) const
  • QWidget * screen ( intscreen = -1 )
  • const QRect & screenGeometry ( intscreen = -1 ) const

Detailed Description

The QDesktopWidget class provides access to screen information on multi-head systems.

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, which usually has the size of the bounding rectangle of all the screens (see isVirtualDesktop()). For an application, one of the available screens is the primary screen, i.e. the screen where the main widget resides (see primaryScreen()). All windows opened in the context of the application must 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.

The QDesktopWidget provides information about the geometry of the available screens with screenGeometry(). The number of screens available is returned by numScreens(). The screen number that a particular point or widget is located in is returned by screenNumber().

Widgets provided by Qt use this class, for example, to place tooltips, menus and dialog boxes according to the parent or application widget.

Applications can use this class to save window positions, or to place child widgets on one screen.

Managing Multiple Screens

In the illustration above, Application One's primary screen is screen 0, and App Two's primary screen is screen 1.

See also Advanced Widgets and Environment Classes.


Member Function Documentation

QDesktopWidget::QDesktopWidget ()

Creates the desktop widget.

If the system supports a virtual desktop, this widget will have the size of the virtual desktop; otherwise this widget will have the size of the primary screen.

Instead of using QDesktopWidget directly, use QAppliation::desktop().

QDesktopWidget::~QDesktopWidget ()

Destroy the object and free allocated resources.

bool QDesktopWidget::isVirtualDesktop () const

Returns TRUE if the system manages the available screens in a virtual desktop; otherwise returns FALSE.

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

int QDesktopWidget::numScreens () const

Returns the number of available screens.

See also primaryScreen().

int QDesktopWidget::primaryScreen () const

Returns the index of the primary screen.

See also numScreens().

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

Returns a widget that represents the screen with index screen. This widget can be used to draw directly on the desktop, using an unclipped painter like this:

    QPainter paint( QApplication::desktop()->screen( 0 ), TRUE );
    paint.draw...
    ...
    paint.end();
    

If the system uses a virtual desktop, the returned widget will have the geometry of the entire virtual desktop i.e. bounding every screen.

See also primaryScreen(), numScreens() and isVirtualDesktop().

constQRect& QDesktopWidget::screenGeometry ( intscreen = -1 ) const

Returns the geometry of the screen with index screen.

See also screenNumber().

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

Returns the index of the screen that contains the largest part of widget, or -1 if the widget is not on a screen.

See also primaryScreen().

int QDesktopWidget::screenNumber ( constQPoint&point ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the index of the screen that contains point, or -1 if no screen contains the point.

See also primaryScreen().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文