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. QML Binding Loop when childrenrect is used.
Forum Updated to NodeBB v4.3 + New Features

QML Binding Loop when childrenrect is used.

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

    Hello,
    I have a simple application as below :

    import QtQuick 2.6
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("App1")
    
        Item {
            id: panel
            anchors.verticalCenter: parent.verticalCenter
            anchors.verticalCenterOffset: 1
            visible: true
            width: childrenRect.width + 11
    
            Image {
                id: divider
                visible: true
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                source:"/../Desktop/51x51_button_activepressed.png"
            }
        }
    }
    
    

    Problem is i am seeing qml warning "qrc:/main.qml:10:5: QML Item: Binding loop detected for property "width"" on running this piece of code.

    If the horizontal and vertical centers are removed form the image, then the code runs without any error.

    But there are certain use cases in my actual applications where i wish to retain the horizontal and vertical positioners.

    Please help me in understanding binding loop warning upon using "childrenrect.width".

    Thanks in advance.

    J.HilkJ 1 Reply Last reply
    0
    • L Offline
      L Offline
      Laszlo LG
      wrote on last edited by
      #2

      The Image calculates its horizontal center from the parent's horizontal center which I guess is calculated from its width but that comes from the child's width so there is a loop.

      This is just a wild guess so I hope others will clarify this and let us know where the source codes of the relevant QML definitions are.

      N 1 Reply Last reply
      1
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Use width: divider.width + 11.

        childrenRect looks comes with four parameters including x, y.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        N 1 Reply Last reply
        1
        • N Nitheesh

          Hello,
          I have a simple application as below :

          import QtQuick 2.6
          import QtQuick.Window 2.2
          
          Window {
              visible: true
              width: 640
              height: 480
              title: qsTr("App1")
          
              Item {
                  id: panel
                  anchors.verticalCenter: parent.verticalCenter
                  anchors.verticalCenterOffset: 1
                  visible: true
                  width: childrenRect.width + 11
          
                  Image {
                      id: divider
                      visible: true
                      anchors.horizontalCenter: parent.horizontalCenter
                      anchors.verticalCenter: parent.verticalCenter
                      source:"/../Desktop/51x51_button_activepressed.png"
                  }
              }
          }
          
          

          Problem is i am seeing qml warning "qrc:/main.qml:10:5: QML Item: Binding loop detected for property "width"" on running this piece of code.

          If the horizontal and vertical centers are removed form the image, then the code runs without any error.

          But there are certain use cases in my actual applications where i wish to retain the horizontal and vertical positioners.

          Please help me in understanding binding loop warning upon using "childrenrect.width".

          Thanks in advance.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Nitheesh

          Image has also a sourceSize property. you could use that, to get the Image's width


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • dheerendraD dheerendra

            Use width: divider.width + 11.

            childrenRect looks comes with four parameters including x, y.

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

            @dheerendra Thanks a lot!.. Worked alright for me..

            1 Reply Last reply
            0
            • L Laszlo LG

              The Image calculates its horizontal center from the parent's horizontal center which I guess is calculated from its width but that comes from the child's width so there is a loop.

              This is just a wild guess so I hope others will clarify this and let us know where the source codes of the relevant QML definitions are.

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

              @Laszlo-LG thank you for the explanation

              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