3

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?

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

Edit: 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();
}

The debug output is: 2

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.

IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
OnurA
  • 611
  • 2
  • 11
  • 25
  • If you're on Ubuntu, why are you reading the embedded linux documentation? :-/ In the regular Qt5 docs you'll find [QScreen](http://doc.qt.io/qt-5/qscreen.html) and [QWindow::setScreen()](http://doc.qt.io/qt-5/qwindow.html#setScreen)... which I've not used but may suit your purpose. – HostileFork says dont trust SE Apr 07 '16 at 11:25

2 Answers2

6

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

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

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

OnurA
  • 611
  • 2
  • 11
  • 25
johngull
  • 819
  • 6
  • 22
  • move function of which class? – OnurA Apr 07 '16 at 12:59
  • @OnurA `move` function of QQuickView in your case. Like `view1.move(screen1->geometry().x(),screen1->geometry().y());` – johngull Apr 07 '16 at 13:00
  • it doesn't have any move function? Can you find it from the Qt 5 documentation? – OnurA Apr 07 '16 at 13:03
  • @OnurA, you are right. Mixed up with the QtWidget classes. – johngull Apr 07 '16 at 13:05
  • @OnurA, what a output. seems stackoverflow cut it. – johngull Apr 07 '16 at 13:08
  • no I deleted it because the reason was a small bug in my code. It worked as you suggested with the setGeometry method. – OnurA Apr 07 '16 at 13:10
  • it is still interesting that setScreen didn't work and setGeometry is enough without the setScreen method. Now I just have setGeometry() and show() and that's it – OnurA Apr 07 '16 at 13:13
  • 1
    @OnurA, you will need `setScreen` in case if you will call `showFullScreen`. Probably it is important in some other situations, but that is only one i faced. – johngull Apr 07 '16 at 13:14
1

I suggest you to take a look at this question and this answer on another question. Also, refer to the documentation of QDesktopWidget. Hope that helps !

Community
  • 1
  • 1
IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
  • Is [this](http://stackoverflow.com/questions/31298810/multiple-windows-in-a-single-project) relevant? – IAmInPLS Apr 07 '16 at 12:38