I’ve got a PyQt5 application that needs to run on a variety of different PC’s with different single- or multi-monitor display set-ups. It needs to arrange multiple child windows across multiple screens programmatically based on optimising the space available. However PyQt5 is returning some very confusing and apparently wrong values for the available screen geometry.
On one test PC, the Windows desktop arrangement is like this:
All three of these displays have a scale setting of 150%. The large displays have a display resolution of 3840 x 2160.
When I iterate QApplication.screens() and get the geometry() of each of the screens, I get (from left to right):
[PyQt5.QtCore.QRect(-2880, 1607, 2880, 1620),
PyQt5.QtCore.QRect(0, 0, 3840, 2160),
PyQt5.QtCore.QRect(5760, 0, 3840, 2160)]
I don’t understand why the right-hand monitor has an origin point of 5760,0 if the centre display is only 3840px wide? This essentially creates an island between the two large monitors which, according to the screen geometry, isn’t even there. An unscientific mockup of it would look like this:
The numbers between the left and centre monitor look fine, but the right-hand monitor is off.
Furthermore, if I want to programmatically move a window onto the right hand monitor, the position it expects in a move() call would be 5760,0. Calling move(3840,0), which feels like it ought to place the window on the right-hand monitor, ends up partway across the central monitor.
There’s an apparent inconsistency between the scaling values for position and size, and I am struggling to find a workaround for it. I can’t seem to find a screen parameter (logicalDotsPerInch, devicePixelRatio etc.) that I could use to compensate for the gap, without ruining the valid values between the centre and left monitors.
Has anyone encountered this before and worked out a reliable way of getting the PyQt-friendly dimensions of all the screens, properly scaled and ready for use in a move()?
The Windows process is DPI-aware, which is essential for other reasons, and the Qt.AA_EnableHighDpiScaling attribute on the application is set to True already, though changing it to False doesn’t seem to make any difference.
Thanks