简体   繁体   English

强制 Qt-Window 到特定屏幕

[英]Force Qt-Window to specific screen

I have a Windows-system with two monitors connected to it that itself expand the Windows-desktop.我有一个 Windows 系统,有两个显示器连接到它,它本身扩展了 Windows 桌面。 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).现在我想启动两个 Qt 应用程序,但需要强制它们每个到一个特定的监视器,这意味着应用程序 A 总是必须在监视器 1 上打开它的窗口,应用程序 B 总是必须在监视器 2 上打开它的窗口(无论它们在哪里上次打开时,无论鼠标当前位于何处)。

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?如果是:如何将基于 QWidget 的窗口强制到特定坐标? If no: how else can this be done?如果不是:还能怎么做?

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()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM