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. Why is item width 0 when using anchors.fill: parent?
QtWS25 Last Chance

Why is item width 0 when using anchors.fill: parent?

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

    Hello forum members, I'm strugglin to create a dynamic row component. It seems to be related to the problem that it's width is 0, although it spans the whole window.
    Minimal example code using a rectangle instead of a row below:

    Window {
        id: testWin
        title: "WDC Test View"
    
        Rectangle {
            border.color: "red"
            border.width: 2
            color: "orange"
            anchors.fill: parent
            Component.onCompleted: console.log(width)
        }
    }
    

    Looks like this on my computer:
    ![picture](0_1534535931240_Screenshot_20180817_215816.png
    Console output is "0". But i would expect the window width.
    Why isn't the width set to the rectangles real width?
    How could I get the real width?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gaess
      wrote on last edited by
      #2

      Answering my own post. It seems that the item width is 0 onComplete and width changed afterwards. So following code will output the window width:

      Window {
          id: testWin
          title: "WDC Test View"
      
          Rectangle {
              border.color: "red"
              border.width: 2
              color: "orange"
              anchors.fill: parent
              onWidthChanged: console.log(width)
          }
      }
      
      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