PDA

View Full Version : QDesktopWidget and multiple monitors



drmacro
2nd August 2017, 18:03
I want to position my main window at start up.

It appears QDesktopWidget().screenGeometry() returns a QRect().

This appears to only have the width of one monitor of the virtual desktop (this is on Linux). In this particular set of hardware that's 0,0,1920,1080.

I can see with .screenCount that there are two monitors and .screenGeometry(x) returns the QRect of the associated screen (i.e. x = 0 or x = 1)

This is a QDialog set geometry will size the dialog, but, I don't see how to get it onto a specific screen (i.e. 0 or 1)

Confuse. :p

d_stranz
2nd August 2017, 19:48
QDesktopWidget is derived from QWidget. You can call QWidget::width() and QWidget::height() on the QDesktopWidget instance, and that will return the dimensions of the entire virtual screen (i.e. the width of both screens combined).

Your display driver setup is what determines which screen is 0 and which is 1; most of the time systems are configured so screen 0 is on the left.

So I am pretty sure the way you get your app to appear on screen 1 is to get the width of screen 0, then call setPos() on your top-level widget (QMainWindow) so that its x coordinate is greater than the width of screen 0. I don't have a dual screen setup so I can't test it.

drmacro
7th August 2017, 19:31
Seems that is how it works.