Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dragging a frameless window across mixed DPI monitors
Qt 6.11 is out! See what's new in the release blog

Dragging a frameless window across mixed DPI monitors

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 299 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vscfreire
    wrote last edited by
    #1

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

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      Even though it's private you should take a look at qhighdpiscaling_p.h (QtGui) and maybe also in it's sources.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      V 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Even though it's private you should take a look at qhighdpiscaling_p.h (QtGui) and maybe also in it's sources.

        V Offline
        V Offline
        vscfreire
        wrote last edited by
        #3

        @Christian-Ehrlicher Thanks, I will check that out

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved