Add PropertyChanges to a State in a derived QML component



  • Hi all,

    I have a QML component "comp1" which defines a state "state1" and a 2nd component comp2 which derives from comp1. Now I want to add (!) a PropertyChanges definition in comp2 to the state derived from comp1 without overriding the definitions in comp1. How can I achieve that?

    comp1.qml:

    Item {
      id: item
      property color color1: "white"
      states: [
        State: {
          name: "state1"
          PropertyChanges { target: item; color1: "green" }
        }
      ]
    }
    

    comp2.qml:

    Comp1 {
      id: item
      property color color2: "black"
      states: [
        State: {
          name: "state1"
          PropertyChanges { target: item; color2: "red" }
        }
      ]
    }
    

    main.qml:

    ...
    Comp2 {
      state: "state1"
    }
    ...
    


  • @DuBu 'states' is a (javascript) array of objects, maybe you can manipulate State objects dynamically in Component.onCompleted. Loop through the array and find the object where the property 'name' is "state1". Then take the first object in the 'changes' array and manipulate it.



  • @Eeli-K I'll give it a try, but it forces me to leave the declarative way.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.