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. [SOLVED] Getting anchors from C++

[SOLVED] Getting anchors from C++

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.8k 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.
  • J Offline
    J Offline
    jhndnn
    wrote on last edited by
    #1

    I have class which derives from QDeclarativeItem. In its geometryChanged() method I want to layout the children. I'd like to respect the anchors which are assigned to the children - how can I get the anchors property of a QDeclarativeItem?

    If I call QDelarativeItem::property("anchors") I get a QVariant, which contains a QDeclarativeAnchors*. I can't figure out how to pull a QObject* out of a QVariant. I've tried qVariantValue<QObject*>() but that returns null. QDeclarativeAnchors is a private class so I can't cast to that.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      florent.revelut
      wrote on last edited by
      #2

      I haven't played with QML (yet), but having a look at the doc, couldn't you get something out of
      "QDeclarativeProperty":http://doc.qt.nokia.com/4.7/qdeclarativeproperty.html ?

      Something like
      @
      QDeclarativeProperty p(yourObject,"anchors");
      QObject *pObj = p.object()
      @

      No clue if it will work, but from the doc, it's worth a try.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jhndnn
        wrote on last edited by
        #3

        Thanks. This works
        @
        double l = QDeclarativeProperty(child, "anchors.leftMargin").read().toDouble();
        @

        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