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. Dynamic height for rectangle
Forum Updated to NodeBB v4.3 + New Features

Dynamic height for rectangle

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 5.7k 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
    neda
    wrote on last edited by
    #1

    Hi,
    I am using this code for display the resolution of camera. I want to set dynamic height for rectangle but I have this error in application output:

    QML Rectangle: Binding loop detected for property "height"
    
    Item {
        
        id: dialogComponent
        anchors.fill: parent
    
        PropertyAnimation { target: dialogComponent; property: "opacity";
            duration: 400; from: 0; to: 1;
            easing.type: Easing.InOutQuad ; running: true }
    
        Rectangle {
            anchors.fill: parent
            id: overlay
            color: "#000000"
            opacity: 0.6
            MouseArea {
                anchors.fill: parent
            }
        }
    
        Rectangle {
            id: dialogWindow
            width: textDialog.width+50
            height:cl.height+150
            radius: 4
            anchors.centerIn: parent
    
            Image {
                id: close
                source: "images/close.png"
                anchors.horizontalCenter: parent.right
    
                MouseArea{
                    anchors.fill: parent
                    onClicked: {
                        dialogComponent.destroy()
                    }
                }
                layer.enabled: true
                layer.effect: DropShadow {
                    radius: 4
                    samples: radius * 2
                    source: close
                    color: Qt.rgba(0, 0, 0, 0.5)
                    transparentBorder: true
                    verticalOffset: 2
                }
            }
    
            ColumnLayout{
                id: cl
                spacing: 10
                anchors.centerIn: parent
                anchors.fill: parent
                anchors.leftMargin: 30
                RowLayout{
    
                    MyText {
                        id:textDialog
    
                        MouseArea{
                            anchors.fill: parent
                            onClicked: {
                                dialogComponent.destroy()
                            }
                        }
                    }
                }
                RowLayout {
                    Grid{
                        columns: 1
                        spacing: 10
    
                        ExclusiveGroup {
                            id: myListExclusiveGroup
                        }
                        Repeater {
                            id: myList
    
                            MyRadioButton {
                                text: modelData.width + "x" + modelData.height
                                exclusiveGroup: myListExclusiveGroup
                                anchors.leftMargin: 50
                                onCheckedChanged: {
                                    ....
                                }
                                Component.onCompleted: {
                                    ....
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! This is what causes the binding loop:

      Rectangle {
               id: dialogWindow
               height:cl.height+150
      // ...
               ColumnLayout{
                   id: cl
                   anchors.fill: parent
      
      N 1 Reply Last reply
      0
      • ? A Former User

        Hi! This is what causes the binding loop:

        Rectangle {
                 id: dialogWindow
                 height:cl.height+150
        // ...
                 ColumnLayout{
                     id: cl
                     anchors.fill: parent
        
        N Offline
        N Offline
        neda
        wrote on last edited by neda
        #3

        @Wieland

        Yes,I know, but how I fix this problem?
        I do not know the number of items. How do I adjust the height?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          E.g. like this:

          Main.qml

          import QtQuick 2.6
          import QtQuick.Controls 1.5
          import QtQuick.Layouts 1.1
          
          ApplicationWindow {
              visible: true
              width: 640
              height: 480
              title: qsTr("Hello World")
          
              MyItem { anchors.centerIn: contentItem }
          }
          

          MyItem.qml

          import QtQuick 2.6
          import QtQuick.Controls 1.5
          import QtQuick.Layouts 1.1
          
          Item {
              width: myRectangle.width
              height: myRectangle.height
              
              property int myMargin: 15
          
              Rectangle {
                  id: myRectangle
                  width: myColumnLayout.width + myMargin
                  height: myColumnLayout.height + myMargin
                  radius: 5
                  border.width: 1
              }
          
              ColumnLayout {
                  id: myColumnLayout
                  x: myMargin / 2
                  y: myMargin / 2
                  Rectangle { width: 50; height: 50; color: "orange" }
                  Rectangle { width: 50; height: 50; color: "pink" }
                  Rectangle { width: 50; height: 50; color: "plum" }
                  Rectangle { width: 50; height: 50; color: "lime" }
              }
          }
          
          N 1 Reply Last reply
          1
          • ? A Former User

            E.g. like this:

            Main.qml

            import QtQuick 2.6
            import QtQuick.Controls 1.5
            import QtQuick.Layouts 1.1
            
            ApplicationWindow {
                visible: true
                width: 640
                height: 480
                title: qsTr("Hello World")
            
                MyItem { anchors.centerIn: contentItem }
            }
            

            MyItem.qml

            import QtQuick 2.6
            import QtQuick.Controls 1.5
            import QtQuick.Layouts 1.1
            
            Item {
                width: myRectangle.width
                height: myRectangle.height
                
                property int myMargin: 15
            
                Rectangle {
                    id: myRectangle
                    width: myColumnLayout.width + myMargin
                    height: myColumnLayout.height + myMargin
                    radius: 5
                    border.width: 1
                }
            
                ColumnLayout {
                    id: myColumnLayout
                    x: myMargin / 2
                    y: myMargin / 2
                    Rectangle { width: 50; height: 50; color: "orange" }
                    Rectangle { width: 50; height: 50; color: "pink" }
                    Rectangle { width: 50; height: 50; color: "plum" }
                    Rectangle { width: 50; height: 50; color: "lime" }
                }
            }
            
            N Offline
            N Offline
            neda
            wrote on last edited by
            #5

            @Wieland Thank you so much

            ? 1 Reply Last reply
            0
            • N neda

              @Wieland Thank you so much

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @neda You're welcome :-)

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved