对于QWidget程序:
- QApplication a(argc, argv);
- MainWindow w;
-
- // 获取屏幕指针列表
- QList
screenList = QGuiApplication::screens(); - QRect rect = screenList[0]->geometry(); // 若有多个屏幕,可选择不同的下标0,1,2......
- qDebug() << "rect=" << rect;
- w.setGeometry(rect);
-
- w.show();
- return a.exec();
QML程序:
- Window {
- id: root
-
- width: 1920
- height: 720
-
- //方法在所有平台并不是通用的
- //方法1:
- //screen: Qt.application.screens[1]
-
- //方法2
- x: Qt.application.screens[1].virtualX
- y: Qt.application.screens[1].virtualY
- }
以两个屏幕,都是1920x1080 windows为例:
QRect rect = screenList[0]->geometry();rect0= QRect(0,0 1920x1080);
rect1= QRect(1920,0 1920x1080);
屏幕1和2的的起点坐标是不一样的。