admin管理员组文章数量:1570220
双屏幕显示
界面程序,需要启动2个实例,分别放在两个屏幕上:
实现方式:
QDesktopWidget *desktop = QApplication::desktop();
int screenNum = desktop->numScreens();
1
2
获取当前环境的屏幕个数,如果为2个屏幕,返回值为2。
根据屏幕索引号获取屏幕位置,如果为2个屏幕,默认计算机主屏幕index=0,外接显示器index = 1:
int index=1;
QRect rect = desktop->screenGeometry(index);
1
2
在显示窗口前,调用setGeometry。
MainWindow* window = new MainWindow (NUll);
window ->setGeometry(rect);
window ->show();
另外一个实例采用相同的方式设定显示的屏幕。
注:
之前尝试使用QWidget *screen(int screen = -1);直接获取当前屏幕对于的QWidget 对象,发现不能生效。
QDesktopWidget *desktop = QApplication::desktop();
QWidget *parent = desktop -> screen(1);
MainWindow* window = new MainWindow (parent);
最后发现,在使用Qt-4.8版本中,windows下该接口没有实际功能。
/*qdesktopwidget_win.cpp*/
QWidget *QDesktopWidget::screen(int /* screen */)
{
// It seems that a Qt::WType_Desktop cannot be moved?
return this;
}
双屏幕间拖动
在主窗口类下,
mousePressEvent中,保存窗口原来的窗口索引old_index ;
mouseReleaseEvent获取当前的索引,如果与old_index不同,发送信号,通知切换屏幕;
切换屏幕槽函数:
void MainWindow::slotSwitchScreen(const int nScreenNo)
{
QRect oRect = QApplication::desktop()->screenGeometry(nScreenNo);
this->move(oRect.topLeft());
this->showFullScreen();
}
原文:https://blog.csdn/weixin_39763552/article/details/80422990
版权声明:本文标题:Qt窗口双屏幕显示及拖动 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727666593a1124683.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论