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. setProperty on a scoped property (like "border.color")?
Forum Updated to NodeBB v4.3 + New Features

setProperty on a scoped property (like "border.color")?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 1.0k 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.
  • A Offline
    A Offline
    allany
    wrote on last edited by
    #1

    Hello,

    I my QML file, I have a Rectangle named "thumb". I'd like to be able to change its colors from C++...

    QObject *thumb = findChild<QObject*>("thumb");
    if (thumb) {
        thumb->setProperty("color", "red");
        thumb->setProperty("border.color", "red");
    }
    

    When the code above is executed, the "color" property gets set, but the "border.color" property does not (and that line returns false).

    Should it be possible to change a scoped/nested property such as "border.color" using setProperty()? Or is there an alternate method or syntax for this?

    Thank you.
    -Allan

    A 1 Reply Last reply
    0
    • A allany

      Hello,

      I my QML file, I have a Rectangle named "thumb". I'd like to be able to change its colors from C++...

      QObject *thumb = findChild<QObject*>("thumb");
      if (thumb) {
          thumb->setProperty("color", "red");
          thumb->setProperty("border.color", "red");
      }
      

      When the code above is executed, the "color" property gets set, but the "border.color" property does not (and that line returns false).

      Should it be possible to change a scoped/nested property such as "border.color" using setProperty()? Or is there an alternate method or syntax for this?

      Thank you.
      -Allan

      A Offline
      A Offline
      allany
      wrote on last edited by allany
      #2

      ...and here's a related issue:

      Assume that my Rectangle has this Behavior attached to its border.color property:

              Behavior on border.color {
                  objectName: "thumb_color_behavior"
                  enabled: false
                  ColorAnimation {
                      duration: 250
                      easing.type: Easing.Linear
                  }
              }
      

      In C++, I try to get this Behavior object:

      QObject *thumb = findChild<QObject*>("thumb_color_behavior");
      if (thumb) {
          thumb->setProperty("enabled", true);
      }
      

      ...however, the findChild call returns NULL.

      But note (and this relates to my initial question)...if the Behavior was attached to a non-scoped property such as "color" (instead of "border.color"), then the findChild call would succeed.

      @allany

      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