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 position of QML Items in C++?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 716 Views
  • 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 Offline
    L Offline
    likewise
    wrote on last edited by
    #1

    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.HilkJ 1 Reply Last reply
    0
    • L likewise

      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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      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


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

      1 Reply Last reply
      4
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        Do you need it only for debugging?

        Maybe GammaRay can help you.

        1 Reply Last reply
        5
        • L Offline
          L Offline
          likewise
          wrote on last edited by likewise
          #4

          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
          0

          • Login

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