Reputation: 6193
I have a Windows-system with two monitors connected to it that itself expand the Windows-desktop. Now I want to start two Qt-applications but need to force each of them to a specific monitor, means application A always has to open it's window on monitor 1, application B always has to open it's window on monitor 2 (no matter where they have been opened the last time and no matter where the mouse is located at the moment).
How can this be done automatically? Can it only be done via the screen-coordinates of the desktop? If yes: how can I force my QWidget-based window to a specific coordinate? If no: how else can this be done?
Upvotes: 3
Views: 4562
Reputation: 3132
To get the number of screens at runtime you can use:
int screenCount = QApplication::desktop()->screenCount();
To get the geometry of a screen, you can use:
QRect screenRect = QApplication::desktop()->screenGeometry(1); // 0-indexed, so this would get the second screen
Moving a window to that position (or resizing it) is then trivial:
yourWindow->move(QPoint(screenRect.x(), screenRect.y()));
Upvotes: 8