Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to get absolute Item position

How to get absolute Item position

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 4.8k 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.
  • M Offline
    M Offline
    maurofaresoftware.it
    wrote on last edited by
    #1

    Hi all.
    There is a way to get the absolute (x,y) position of an Item in the screen?
    There only one screen in the system

    Best regards,
    MZ

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Use Item.mapToGlobal(). This will return you global coordinate inside the window. Then you need to use Window's properties to get the window coordinates: https://doc.qt.io/qt-5/qml-qtquick-window-window.html#x-prop

      (Z(:^

      B 1 Reply Last reply
      1
      • sierdzioS sierdzio

        Use Item.mapToGlobal(). This will return you global coordinate inside the window. Then you need to use Window's properties to get the window coordinates: https://doc.qt.io/qt-5/qml-qtquick-window-window.html#x-prop

        B Offline
        B Offline
        Bob64
        wrote on last edited by Bob64
        #3

        @sierdzio I think mapToGlobal maps to screen rather than window coordinates, so the OP can use the value without further adjustment. I say this because it was confusing me last week - I was initially working on the assumption that it did map to window coordinates. Once I realised, I used the window's position to map the screen coordinates from mapToGlobal to be relative to the main window.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @Bob64 If that's the case, the whole thing becomes even easier :-) Thanks

          (Z(:^

          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 Extensions
          • Unsolved