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. Standard qml Property binding is not read properly.

Standard qml Property binding is not read properly.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 724 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.
  • N Offline
    N Offline
    Nitheesh
    wrote on last edited by
    #1

    I have a bool property which is updated based on another property as shown below code

    import QtQuick 2.6
    import QtQuick.Window 2.2
    
    Window {
       id: main1
       visible: true
       width: 1024
       height: 720
       title: qsTr("Hello World")
       property bool validator: rect1.color !== "red" ? false : true
    
       Row {
           id: root
           width: parent.width
           height: parent.height
    
           Repeater {
               id:rp1
               model: 10
    
               Rectangle {
                   id:rect1
                   visible: true
                   color: "red"
                   height: 50
                   width: 50
                   MouseArea {
                       anchors.fill: parent
                       onClicked: rect1.color = "green"
                   }
               }
           }
       }
    
       Rectangle {
           id: rect2
           anchors.bottom: parent.bottom
           color: "Yellow"
           width: 100
           height: 75
           visible: !validator
       }
    }
    

    The above code is just a sample. Here property "validator" is not updating whenever rectangle inside Repeater is clicked. However the color of rectangle is changing individually to green. But if the property change was caught by qml, then the rect2 should be invisible. Curious why internal qml property is not recognizing this change. Request to help

    Thanks in advance.

    raven-worxR M 2 Replies Last reply
    0
    • N Nitheesh

      I have a bool property which is updated based on another property as shown below code

      import QtQuick 2.6
      import QtQuick.Window 2.2
      
      Window {
         id: main1
         visible: true
         width: 1024
         height: 720
         title: qsTr("Hello World")
         property bool validator: rect1.color !== "red" ? false : true
      
         Row {
             id: root
             width: parent.width
             height: parent.height
      
             Repeater {
                 id:rp1
                 model: 10
      
                 Rectangle {
                     id:rect1
                     visible: true
                     color: "red"
                     height: 50
                     width: 50
                     MouseArea {
                         anchors.fill: parent
                         onClicked: rect1.color = "green"
                     }
                 }
             }
         }
      
         Rectangle {
             id: rect2
             anchors.bottom: parent.bottom
             color: "Yellow"
             width: 100
             height: 75
             visible: !validator
         }
      }
      

      The above code is just a sample. Here property "validator" is not updating whenever rectangle inside Repeater is clicked. However the color of rectangle is changing individually to green. But if the property change was caught by qml, then the rect2 should be invisible. Curious why internal qml property is not recognizing this change. Request to help

      Thanks in advance.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Nitheesh said in Standard qml Property binding is not read properly.:

      rect1.color !== "red"

      is true whenever the color is not the string "red", which is always the case.
      You should use Qt.colorEqual() instead for the check

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      N 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @Nitheesh said in Standard qml Property binding is not read properly.:

        rect1.color !== "red"

        is true whenever the color is not the string "red", which is always the case.
        You should use Qt.colorEqual() instead for the check

        N Offline
        N Offline
        Nitheesh
        wrote on last edited by
        #3

        @raven-worx Thanks for the reply! As per you changed the code to Qt.colorEqual() check. Still Property is not caught properly. Let me put it in this way, instead of color will change the height of the rectangle and corresponding bool check shall be assigned to variable validator as in code below:

        import QtQuick 2.6
        import QtQuick.Window 2.2
        
        Window {
            id: main1
            visible: true
            width: 1024
            height: 720
            title: qsTr("Hello World")
            property bool validator: rect1.height === 50 ? false : true
        
            Row {
                id: root
                width: parent.width
                height: parent.height
        
                Repeater {
                    id:rp1
                    model: 10
        
                    Rectangle {
                        id:rect1
                        visible: true
                        color: "red"
                        height: 50
                        width: 50
                        MouseArea {
                            anchors.fill: parent
                            onClicked: rect1.height = 200
                        }
                    }
                }
            }
        
            Rectangle {
                id: rect2
                anchors.bottom: parent.bottom
                color: "Yellow"
                width: 100
                height: 75
                visible: !validator
            }
        }
        
        

        Even in this case the rect2 is not invisible upon click of rect1 except only height of rect1 changes.

        raven-worxR 1 Reply Last reply
        0
        • N Nitheesh

          @raven-worx Thanks for the reply! As per you changed the code to Qt.colorEqual() check. Still Property is not caught properly. Let me put it in this way, instead of color will change the height of the rectangle and corresponding bool check shall be assigned to variable validator as in code below:

          import QtQuick 2.6
          import QtQuick.Window 2.2
          
          Window {
              id: main1
              visible: true
              width: 1024
              height: 720
              title: qsTr("Hello World")
              property bool validator: rect1.height === 50 ? false : true
          
              Row {
                  id: root
                  width: parent.width
                  height: parent.height
          
                  Repeater {
                      id:rp1
                      model: 10
          
                      Rectangle {
                          id:rect1
                          visible: true
                          color: "red"
                          height: 50
                          width: 50
                          MouseArea {
                              anchors.fill: parent
                              onClicked: rect1.height = 200
                          }
                      }
                  }
              }
          
              Rectangle {
                  id: rect2
                  anchors.bottom: parent.bottom
                  color: "Yellow"
                  width: 100
                  height: 75
                  visible: !validator
              }
          }
          
          

          Even in this case the rect2 is not invisible upon click of rect1 except only height of rect1 changes.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Nitheesh said in Standard qml Property binding is not read properly.:

          rect1.height === 50

          same problem again.
          You first need to understand that === is only true if the value AND the type matches. Now you are comparing real to int.
          So either use == only or rect1.height === 50.0

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • N Nitheesh

            I have a bool property which is updated based on another property as shown below code

            import QtQuick 2.6
            import QtQuick.Window 2.2
            
            Window {
               id: main1
               visible: true
               width: 1024
               height: 720
               title: qsTr("Hello World")
               property bool validator: rect1.color !== "red" ? false : true
            
               Row {
                   id: root
                   width: parent.width
                   height: parent.height
            
                   Repeater {
                       id:rp1
                       model: 10
            
                       Rectangle {
                           id:rect1
                           visible: true
                           color: "red"
                           height: 50
                           width: 50
                           MouseArea {
                               anchors.fill: parent
                               onClicked: rect1.color = "green"
                           }
                       }
                   }
               }
            
               Rectangle {
                   id: rect2
                   anchors.bottom: parent.bottom
                   color: "Yellow"
                   width: 100
                   height: 75
                   visible: !validator
               }
            }
            

            The above code is just a sample. Here property "validator" is not updating whenever rectangle inside Repeater is clicked. However the color of rectangle is changing individually to green. But if the property change was caught by qml, then the rect2 should be invisible. Curious why internal qml property is not recognizing this change. Request to help

            Thanks in advance.

            M Offline
            M Offline
            maydin
            wrote on last edited by
            #5

            @Nitheesh Repeater takes a delegate and creates objects according to model.

            Therefore rect1 is not an object, it is a component. Repeater creates 10 Rectangle object, and which one's color will be binded to validator? It does not make sense.

            You should change your design so that it will catch results from signals. For example you can define a single in repeater, and emit it from its children (ie. rectangles) then catch elsewhere.

            N 1 Reply Last reply
            2
            • M maydin

              @Nitheesh Repeater takes a delegate and creates objects according to model.

              Therefore rect1 is not an object, it is a component. Repeater creates 10 Rectangle object, and which one's color will be binded to validator? It does not make sense.

              You should change your design so that it will catch results from signals. For example you can define a single in repeater, and emit it from its children (ie. rectangles) then catch elsewhere.

              N Offline
              N Offline
              Nitheesh
              wrote on last edited by
              #6

              @maydin Thanks a lot!

              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