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

Rounding error in ColumnLayout causes gap between items

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.11, 6.3.2, 6.4.0, 6.4.1
    • Quick: Layouts
    • None
    • Windows 11
    • Windows

    Description

      When a ColumnLayout is resized by changing the window size it sometimes has a sub-pixel gap between items. 

      This looks like QTBUG-41216 except I cannot reproduce QTBUG-41216, but using almost identical code I can reproduce this issue with the code below. Click the window content and the line appears.

      Window {
          id: root
          width: 640
          height: 480
          visible: true
          title: qsTr("Sub-pixel Gap in ColumnLayout")
      
          ColumnLayout {
              anchors.verticalCenter: parent.verticalCenter
              width: root.width
              spacing: 0
      
              Rectangle {
                  Layout.alignment: Qt.AlignHCenter
                  Layout.preferredHeight: root.height * 0.8 // Math.round(root.height * 0.8)
                  Layout.preferredWidth: root.width * 0.55
                  color: "red"
              }
              Rectangle {
                  Layout.alignment: Qt.AlignHCenter
                  Layout.preferredHeight: root.height * 0.1 // Math.round(root.height * 0.1)
                  Layout.preferredWidth: root.width * 0.55
                  color: "blue"
              }
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: root.height -= 0.5
          }
      }

      Using `Math.round()` eliminates the gap.

      I found this while testing a StackOverflow question. What struck me is that the poster's code that rounds the height of the elements prevents the gap from appearing, which leads me to wonder if the cause is a rounding error like QTBUG-41216.

       

      Attachments

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            stan.m Stanley Morris
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: