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. Add PropertyChanges to a State in a derived QML component
Forum Updated to NodeBB v4.3 + New Features

Add PropertyChanges to a State in a derived QML component

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 1.3k Views 2 Watching
  • 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.
  • DuBuD Offline
    DuBuD Offline
    DuBu
    wrote on last edited by DuBu
    #1

    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"
    }
    ...
    
    E 1 Reply Last reply
    0
    • DuBuD DuBu

      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"
      }
      ...
      
      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

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

      DuBuD 1 Reply Last reply
      0
      • E Eeli K

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

        DuBuD Offline
        DuBuD Offline
        DuBu
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nuno Figueiredo
          wrote on last edited by
          #4

          The derived component can have a private object with a state binded to outter scoped state with its own set of property changes:

          Comp1 {
            id: item
            property color color2: "black"  
          
            QtObject {
              id: internal
              state: item.state
          
              states: [
                State: {
                  name: "state1"
                  PropertyChanges { target: item; color2: "red" }
                }
              ]
            }
          }
          
          1 Reply Last reply
          0
          • R Offline
            R Offline
            ratijas
            wrote on last edited by
            #5

            Sorry to bump an old thread, but this is still unsolved and very needed.

            First thing to mention, list<> types are NOT javascript arrays, and can not be manipulated from QML. Which is kinda stupid and inconvenient.

            Second, states can extend each other via extend property. But it does not work well with a when condition: in my case with identical conditions state switches (from default) to subcomponent's overridden extended state, and then immediately to base component's state; so any property changes to subcomponent are undone even before we have a chance to see them.

            As much as I'd like to hear from Qt experts opinion on this matter, it seems list manipulation and subclassing topics are just silently omitted in docs. The only proper solution, in spirit of QML, would be to support such extensions at the language level via special syntax.

            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