Qt Forum

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

    Unsolved How to get position of QML Items in C++?

    QML and Qt Quick
    3
    4
    244
    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.
    • L
      likewise last edited by

      I would like to know what the x, y and width, height of each QML Item is, from C++. Would I need to inspect the QQuickItems or somehow introspect the render nodes? Is there an example or more info on how I can do this?

      Background: We are rendering offscreen / headless. When we switched away from software rendered QWidget/QPainter to QtQuick 2 we lost the information about dirty regions. We need to get this back somehow, as we need this information later.

      J.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @likewise last edited by

        hi @likewise

        the easiest solution is probably to give your qml object an objectName and using findChild to search for the QObject.
        https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#accessing-loaded-qml-objects-by-object-name

        and than simply read the property e.g:
        int x = myObject->property("x").toInt();

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply Reply Quote 4
        • GrecKo
          GrecKo Qt Champions 2018 last edited by

          Do you need it only for debugging?

          Maybe GammaRay can help you.

          1 Reply Last reply Reply Quote 5
          • L
            likewise last edited by likewise

            Thanks, both pointers are useful.

            I need it at run-time. I need to find which changed areas got drawn by the GPU to optimize our GPU to remote screen updates. (i.e. I need the equivalant of QPainter dirty regions.)

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