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. property binding just for initial value

property binding just for initial value

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 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.
  • P Offline
    P Offline
    petzold
    wrote on last edited by
    #1

    Hi,

    in my program all values are stored in a big config.qml
    If i want to use colors, gradients etc. I create a variable and bind it to the master-value in my config.qml.
    Now i have the problem if i want to edit some values like
    value: value * 3
    my "master-value gets the change too and not just the value in the component.

    I tried with readonly property but i get the problem that i can't make readonly Gradients

    Any idea to solve it?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @petzold So how about local property? This will initially be binded to global property in individial components which can then me modified later.

      157

      P 1 Reply Last reply
      0
      • p3c0P p3c0

        @petzold So how about local property? This will initially be binded to global property in individial components which can then me modified later.

        P Offline
        P Offline
        petzold
        wrote on last edited by
        #3

        @p3c0

        That is the way i'm looking for. but how to do?

        property Gradient offGradient: Config.offlineGradient
        

        That is the way i did. I have different gradients for different states.
        Later i modify the actual gradient with

        Qt.darker  
        Qt.lighter
        

        for some mouse-actions (hover, clicked etc.)

        So at the moment i have the problem that my globalConfig.offlineGradient get the change and not just offGradient.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @petzold I was saying something like this:

          Window {
              width: 200
              height: 200
              visible: true
          
              property int globalProperty: 30
          
              Item {
                  id: item
                  property int localProperty: globalProperty
                  anchors.fill: parent
          
                  Text {
                      id: txt
                      anchors.centerIn: parent
                      text: item.localProperty
          
                      MouseArea {
                          anchors.fill: parent
                          onClicked: {
                              item.localProperty = 60
                              console.log(globalProperty)
                          }
                      }
                  }
              }
          }
          

          Initially localproperty holds the globalperoperty. Then on click just changes the localproperty and not global one.

          157

          P 1 Reply Last reply
          0
          • p3c0P p3c0

            @petzold I was saying something like this:

            Window {
                width: 200
                height: 200
                visible: true
            
                property int globalProperty: 30
            
                Item {
                    id: item
                    property int localProperty: globalProperty
                    anchors.fill: parent
            
                    Text {
                        id: txt
                        anchors.centerIn: parent
                        text: item.localProperty
            
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                item.localProperty = 60
                                console.log(globalProperty)
                            }
                        }
                    }
                }
            }
            

            Initially localproperty holds the globalperoperty. Then on click just changes the localproperty and not global one.

            P Offline
            P Offline
            petzold
            wrote on last edited by
            #5

            @p3c0

            Normally that works but i have not so much elements.
            My Element is a Button and it is just a Rectangle with some variables and a mouse area. This button i use as component in other qmls. And now to add additional Items for a workaround i don't want, because i think it is not a "nice" solutions, i hoped that i found a more correct way to "copy" just the value from a property to a new property.
            My actual workaround is to have local propertys and no link to my globalconfig.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              petzold
              wrote on last edited by
              #6

              found a work around.

              just implement the GlobalConfig in following ways

              property QtObject gConfig: GlobalConfig {}
              

              and than

              property Gradient offGradient:		gConfig.offlineGradient
              

              it works

              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