Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    How to get Screen Coordinates of a QML Item?

    QML and Qt Quick
    4
    6
    6161
    Loading More Posts
    • 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
      philk last edited by

      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 Reply Quote 0
      • J
        jsprenkle last edited by

        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 Reply Quote 0
        • P
          philk last edited by

          uhmmm didn't I wrote I use this already?

          1 Reply Last reply Reply Quote 0
          • J
            jsprenkle last edited by

            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 Reply Quote 0
            • L
              lukalease last edited by

              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 Reply Quote 0
              • T
                Timmmm last edited by

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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post