Question on desktop layout with multiple-monitors

  • I am building a QWidgets based desktop application for Windows. The application consists of several windows which can be placed anywhere on the desktop, including across multiple monitors. On shutdown, each of these windows stores in the registry (via. QSettings) its position, and later when the application is run again, each window returns to its last position. This all works just fine.

    The problem I'm trying to work now is, when a user re-runs the application with say one monitor attached. I need to "pull in" each stored position to fit within the current monitor.

    Say for instance, I last saved with 2 monitors, and my position value in settings is @Point(-1200 500) - it was off on the left in the muliti-monitor setup.

    So I figured I could use QApplication::desktop()->screenGeometry() to find the desktop rect, check that the window will fit, and adjust it as needed.

    But to my surprise, when I ran this first on a multi-monitor setup, QApplication::desktop()->screenGeometry(); only returned a rect representing the primary display.

    I guess the question is, if I have a stored window position of, for example @Point(-1200 500) how can I determine if that will put it visible on an actual display, or if I need to offset it?

  • Qt Champions 2016


    maybe you can use the QDesktopWidget

    int QDesktopWidget::screenNumber(const QWidget * widget = 0) const
    Returns the index of the screen that contains the largest part of widget, or -1 if the widget not on a screen.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.