Reputation: 651
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.
Upvotes: 3
Views: 6933
Reputation: 819
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.
Upvotes: 6
Reputation: 4125
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 !
Upvotes: 1