Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54101

Anchoring and binding to parent doesn't work inside Flickable

    XMLWordPrintable

Details

    • aa570a7720dc508f83c32aee81ac1d6ea21d6757

    Description

      The following code use anchoring to parent:

       import QtQuick 2.6
       import QtQuick.Layouts 1.3
       import QtQuick.Window 2.2
       
       Window {
           visible: true
           width: 1000
           height: 400
       
           Flickable {
               id: flickable
       
               height: parent.height
               width: height
               contentHeight: contentRect.implicitHeight
               contentWidth: contentRect.implicitWidth
       
               Rectangle {
                   id: contentRect
       
                   anchors.right: parent.right
                   anchors.left: parent.left
       //            width: flickable.width
       
                   implicitWidth: 800
                   implicitHeight: 800
                   color: "red"
               }
           }
       }
      

      Result in the attachment: instead of width limit, rectangle has wrong width.
      Seems, content item resized to contentWidth, contentHeight and anchoring to it doesn't work properly.

      Another example:

          Flickable {
              id: flickable
      
              width: 320
              height: 240
              contentWidth: column.implicitWidth
              contentHeight: column.implicitHeight
      
              Column {
                  id: column
      
      //            width: flickable.width
      //            width: parent.width
                  anchors.left: parent.left
                  anchors.right: parent.right
                  spacing: 8
      
                  Text {
                      text: parent.width + " x " + parent.height
                      width: parent.width
                      Component.onCompleted: console.log(parent.width, parent.parent.width, parent.parent.parent.width)
                  }
                  Text {
                      text: "this should be wrapped because it's a bit too much text to fit in its parent Column"
                      wrapMode: Text.WordWrap
                      width: parent.width
                  }
                  Text {
                      text: "this should be wrapped too, because it's also a bit too much text to fit in its parent Column"
                      wrapMode: Text.WordWrap
                      width: parent.width
                  }
              }
          }
      

      The only working case, is to bind width to the Flickable by id.

      https://codereview.qt-project.org/#/c/162177/ is an attempt to fix docs, until this bug would be fixed.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            krnekit Nikita Krupenko
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes