Important: Please read the Qt Code of Conduct -

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

  • 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.

  • ...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.


Log in to reply