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 Rectangle:Possible anchor loop detected on horizontal anchor.
Forum Updated to NodeBB v4.3 + New Features

QML Rectangle:Possible anchor loop detected on horizontal anchor.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.1k 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.
  • S Offline
    S Offline
    Swati777999
    wrote on 16 Jul 2021, 07:29 last edited by
    #1

    Hi All,
    Hope you're doing well. I want to create 3 boxex placed adjacent to each other inside a window and add different functionalities . However, I am stuck in the first stage itself. This code doesn't
    provide the required output.

    I am new to QT , in learning and experimentinq phase .Can someone check my code and let me know where the problem lies.

    Any help will be highly appreciated!

    Thanks :)

    import QtQuick 2.6
    import QtQuick.Window 2.2

    Window{
    id: parwindow
    height:500
    width:500
    color:"white"
    title:"Experimenting with anchors "
    x:10
    y:10

    Rectangle {
    id :  rect1
    height: 300
    width : 300
    color: "black"
    anchors.left:parwindow.left
    }
    
    
    Rectangle {
    id: rect2
    height: 300
    width: 300
    color: "green"
    anchors.left: rect1.right
    anchors.right:rect3.left
            }
    
    Rectangle {
        id :rect3
        height:300
        width:300
        color:"blue"
        anchors.left: rect2.right
    }
    

    }

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Markkyboy
      wrote on 16 Jul 2021, 19:35 last edited by
      #2
      import QtQuick 2.12
      import QtQuick.Window 2.12
      
      Window {
          height: 300    /** height of all rects **/
          width: 900     /** width of all rects **/
          color: "white"
          visible: true  /** where was your 'visible' statement ? **/
          title: "Experimenting with anchors"
          x: 10; y: 10
      
          Rectangle {
              id: rect1
              height: 300
              width : height /** if you are making a square, just quote the height **/
              color: "black"
              anchors.left: parent.left /** this is unneccessary, as it will naturally anchors left by default **/
          }
          Rectangle {
              id: rect2
              height: width
              width: 300
              color: "green"
              anchors.left: rect1.right
              /** the anchor here was basically a repeat; you only need to anchor to one side of each, or use 'Row' **/
          }
          Rectangle {
              id: rect3
              height: 300
              width: height
              color: "blue"
              anchors.left: rect2.right
          }
      }
      
      

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      S 1 Reply Last reply 20 Jul 2021, 04:22
      1
      • M Offline
        M Offline
        Markkyboy
        wrote on 16 Jul 2021, 19:40 last edited by
        #3
        import QtQuick 2.12
        import QtQuick.Window 2.12
        
        // Using Row instead of anchoring each rectangle to each other.
        
        Window {
            height: 300
            width: 900
            visible: true
            title: "Experimenting with row"
            x: 10; y: 10
        
            Row {
                id: row
                anchors.horizontalCenter: parent.horizontalCenter
        
                Rectangle {
                    id: rect1
                    height: 300
                    width: height
                    color: "black"
                }
                Rectangle {
                    id: rect2
                    height: 300
                    width: height
                    color: "green"
                }
                Rectangle {
                    id: rect3
                    height: 300
                    width: height
                    color: "blue"
                }
            }
        }
        
        

        Don't just sit there standing around, pick up a shovel and sweep up!

        I live by the sea, not in it.

        S 1 Reply Last reply 20 Jul 2021, 07:30
        1
        • M Markkyboy
          16 Jul 2021, 19:35
          import QtQuick 2.12
          import QtQuick.Window 2.12
          
          Window {
              height: 300    /** height of all rects **/
              width: 900     /** width of all rects **/
              color: "white"
              visible: true  /** where was your 'visible' statement ? **/
              title: "Experimenting with anchors"
              x: 10; y: 10
          
              Rectangle {
                  id: rect1
                  height: 300
                  width : height /** if you are making a square, just quote the height **/
                  color: "black"
                  anchors.left: parent.left /** this is unneccessary, as it will naturally anchors left by default **/
              }
              Rectangle {
                  id: rect2
                  height: width
                  width: 300
                  color: "green"
                  anchors.left: rect1.right
                  /** the anchor here was basically a repeat; you only need to anchor to one side of each, or use 'Row' **/
              }
              Rectangle {
                  id: rect3
                  height: 300
                  width: height
                  color: "blue"
                  anchors.left: rect2.right
              }
          }
          
          
          S Offline
          S Offline
          Swati777999
          wrote on 20 Jul 2021, 04:22 last edited by
          #4

          @Markkyboy

          Just a doubt , whatever width or height was written inside the window, doesn't it define the dimension of the window?

          1 Reply Last reply
          0
          • M Markkyboy
            16 Jul 2021, 19:40
            import QtQuick 2.12
            import QtQuick.Window 2.12
            
            // Using Row instead of anchoring each rectangle to each other.
            
            Window {
                height: 300
                width: 900
                visible: true
                title: "Experimenting with row"
                x: 10; y: 10
            
                Row {
                    id: row
                    anchors.horizontalCenter: parent.horizontalCenter
            
                    Rectangle {
                        id: rect1
                        height: 300
                        width: height
                        color: "black"
                    }
                    Rectangle {
                        id: rect2
                        height: 300
                        width: height
                        color: "green"
                    }
                    Rectangle {
                        id: rect3
                        height: 300
                        width: height
                        color: "blue"
                    }
                }
            }
            
            
            S Offline
            S Offline
            Swati777999
            wrote on 20 Jul 2021, 07:30 last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0

            1/5

            16 Jul 2021, 07:29

            • Login

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