本文记录在Qt5.5.1使用Qdesktopwidget对象实现Qt界面在双屏上显示。
QDesktopWidget* desktop = Application::desktop();
获取当前显示器的个数
N = desktop->screenCount();
如果有两个显示,则N=2,qt默认的计算机主机的index = 0,外接显示器的index = 1;
main.cpp代码:
#include "mainwindow.h"
#include "cong_window.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDesktopWidget* desktop = a.desktop();
int N = desktop->screenCount();
qDebug()<< "desktop->screenCount()="<<N; //显示屏数量
MainWindow w;
Cong_Window cw;
w.setGeometry(desktop->screenGeometry(0));
cw.setGeometry(desktop->screenGeometry(1));
w.show();
cw.show();
return a.exec();
}