Dragging a frameless window across mixed DPI monitors
-
Hi,
I have a frameless window that I would like to make draggable across screens with mixed DPI's.
My initial approach was to implement something similar to https://forum.qt.io/topic/85543/frameless-window-with-dragging which worked for simple drags between positions in the same screen but started to fail (the window began jumping around) when moving between screens of mixed DPI's. I am guessing this is due to the fact that Qt reports logical coordinates for mouse events, meaning there are discontinuities in the reported coordinates when moving the mouse between screens (which explains the jumping around).
My second approach was to get both the mouse and window positions in native coordinates, calculate the window’s target position, and then convert it back to logical coordinates to avoid these gaps. Converting to native coordinates was straightforward: I scaled the window’s dimensions by the device pixel ratio (DPR) of its current screen and adjusted its top-left position accordingly.
Converting back to logical coordinates was trickier. The shift could move the window to another screen, so I needed to know the destination screen’s DPR. However, I had no information about which screen the window would end up on, which made me get stuck as there doesn't seem to be anything in Qt's API that allows me to do this.
With this in mind, I guess I have mainly two questions:
1 - Given a QRect in native coordinates, is there a way to determine which screen it would be on, similar to Win32’s MonitorFromRect?
2 - Is there an alternative better way to do this (without using Native APIs)? -
Even though it's private you should take a look at qhighdpiscaling_p.h (QtGui) and maybe also in it's sources.
-
Even though it's private you should take a look at qhighdpiscaling_p.h (QtGui) and maybe also in it's sources.
@Christian-Ehrlicher Thanks, I will check that out