带有Qt的多个屏幕 [英] Multiple Screens with Qt

查看:46
本文介绍了带有Qt的多个屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Ubuntu 14.04计算机上使用一个Qt应用程序在不同的显示输出(屏幕)上显示两个窗口.有人知道该怎么做吗?

I want to have a single Qt application showing two windows on different display outputs(screens) on my Ubuntu 14.04 computer. Does someone know how to do that?

对于嵌入式Linux,Qt的文档是我能找到的到目前为止,但这并没有真正帮助我.

The documentation of Qt for embedded linux is what I could find so far but it did not help me really.

修改:根据您的评论,我已经完成了此操作,但并没有按预期进行:

Based on your comments, I've done this but it doesn't work as it should:

int main(int argc, char *argv[])
{
  QGuiApplication app(argc, argv);
  QQuickView view1(QUrl(QStringLiteral("qrc:/Screen1.qml")));
  qDebug() << app.screens().length();

  QScreen* screen1 = app.screens().at(0);
  QScreen* screen2 = app.screens().at(1);

  view1.setGeometry(0,0,200,200);
  view1.setScreen(screen1);
  view1.show();

  QQuickView view2(QUrl(QStringLiteral("qrc:/Screen2.qml")));
  view2.setGeometry(0,0,200,200);
  view2.setScreen(screen2);
  view2.show();

  return app.exec();
}

调试输出为: 2

尽管 qDebug 输出给出了正确名称的显示输出,但该代码将两个视图都置于相同的显示输出.

This code is putting both views to the same display output, although the qDebug output gives the correct number of display outputs with correct names.

推荐答案

您的错误是错误的几何.在这两行代码中,将两个窗口都放置在同一位置:

Your mistake is wrong geometry. In these 2 lines of code, you place both windows on same position:

view1.setGeometry(0,0,200,200);
view2.setGeometry(0,0,200,200);

您可以设置位置(不知道是否还需要尺寸):

Instead of this, you can set the position (not sure if you need size also):

view1.setGeometry(screen1->geometry().x(),screen1->geometry().y(),200,200);
view2.setGeometry(screen2->geometry().x(),screen2->geometry().y(),200,200);

要更改位置而不是同时更改位置和大小,可以使用功能 move .

To change the position instead of changing both the position and the size, you can use the function move.

P.S.当我通过内存编写此代码时,可能会有一些小的错别字,但主要思想应该对您清楚.

P.S. There may be some small typos as I wrote this code by memory, but the main idea should be clear for you.

这篇关于带有Qt的多个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆