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 Screen Coordinates of a QML Item?
Forum Updated to NodeBB v4.3 + New Features

How to get Screen Coordinates of a QML Item?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 7.2k Views 1 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.
  • P Offline
    P Offline
    philk
    wrote on 9 Sept 2013, 20:55 last edited by
    #1

    I have a QQuickView that displays a scene. I want to know at which screen coordinate a certain QML item is located at. I know from inside the QML I can call
    @
    myItem.mapToItem(null, myItem.x, myItem.y)
    @
    But I want to give the result (QVariantMap) to a C++ Q_INVOKABLE method that displays a dialog at the position of myItem.x,myItem.y
    It seems I need to map the QQuickView coordinates to Screen coordinates. But how?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsprenkle
      wrote on 13 Sept 2013, 14:58 last edited by
      #2

      Perhaps this function:
      @Item::mapToItem(Item item, real x, real y)@

      documentation:
      "http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-item.html":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-item.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        philk
        wrote on 13 Sept 2013, 19:51 last edited by
        #3

        uhmmm didn't I wrote I use this already?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jsprenkle
          wrote on 13 Sept 2013, 19:59 last edited by
          #4

          Did you read the documentation? Are you having trouble using the function or don't you understand what to do with the results?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lukalease
            wrote on 17 Sept 2013, 01:35 last edited by
            #5

            I recall doing this before. I believe you want

            @myItem.mapToItem(null, 0, 0)@

            Which is the top left corner of myItem relative to myItem. If you use

            @myItem.mapToItem(null, myItem.x, myItem.y)@

            myItem.x and myItem.y are the x/y coordinates relative to myItem's parent object.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Timmmm
              wrote on 13 Jun 2014, 08:21 last edited by
              #6

              None of these are actually screen coordinates. They are all relative to the main window which could be anywhere.

              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