<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Strange ListView behaviour (depending on types of anchors)]]></title><description><![CDATA[<p dir="auto">Why is it that the following two ListViews show up differently? The only difference in the QML is that one is positioned using <code>anchors.fill: parent</code> while the other is positioned using <code>parent.left</code>, <code>.top</code>, <code>.width</code> &amp; <code>.height</code>.</p>
<p dir="auto">Both lists use <code>positionViewAtBeginning()</code> on completed and set the Delegate width to 1/8th ListView width.</p>
<p dir="auto">I suspect it has something to do with the Delegate width having a data binding to the ListView width, since a fixed width behaves 'properly', but the code looks valid to me in both cases.</p>
<p dir="auto"><strong>Case 1</strong></p>
<pre><code>ListView { id: case1
  anchors.fill: parent
  orientation: Qt.Horizontal
  interactive: false

  model: 20
  delegate: Rectangle {
    width: case1.width / 8
    height: case1.height
    border.color: "lightblue"
    border.width: 1

    Text {
      anchors.fill: parent
      horizontalAlignment: Text.AlignHCenter
      verticalAlignment: Text.AlignVCenter
      text: model.index
    }
  }

  Component.onCompleted: positionViewAtBeginning()
}
</code></pre>
<p dir="auto">Positioned at start of list as expected, with cell widths as expected.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/33c2f485-a3bd-46d9-a2c7-91f36d59ecb3.png" alt="Screenshot 2022-09-14 at 11.41.58.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"><strong>Case 2</strong></p>
<pre><code>ListView { id: case2
  anchors.left: parent.left
  anchors.top: parent.top
  width: parent.width //EDIT: corrected typo here
  height: parent.height //EDIT: corrected typo here
  orientation: Qt.Horizontal
  interactive: false

  model: 20
  delegate: Rectangle {
    width: case2.width / 8
    height: case2.height
    border.color: "lightblue"
    border.width: 1

    Text {
      anchors.fill: parent
      horizontalAlignment: Text.AlignHCenter
      verticalAlignment: Text.AlignVCenter
      text: model.index
    }
  }

  Component.onCompleted: positionViewAtBeginning()
}
</code></pre>
<p dir="auto">Neither the position within the list nor the cell widths are as expected.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/e6c60c1c-93d4-4318-a998-b33f02a87778.png" alt="Screenshot 2022-09-14 at 11.42.46.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Delving deeper, I put a <code>console.log()</code> on the <code>Component.onCompleted</code> for both the <code>ListView</code> and the <code>Delegate</code> to output their widths.</p>
<p dir="auto"><strong>Case 1 widths</strong></p>
<pre><code>qml: Delegate 0: -30
qml: Delegate 1: -30
qml: Delegate 2: -30
qml: Delegate 3: -30
qml: Delegate 4: -30
qml: Delegate 5: -30
qml: Delegate 6: -30
qml: Delegate 7: -30
qml: Delegate 8: -30
qml: Delegate 9: -30
qml: Delegate 10: -30
qml: Delegate 11: -30
qml: Delegate 12: -30
qml: Delegate 13: -30
qml: Delegate 14: -30
qml: Delegate 15: -30
qml: Delegate 16: -30
qml: Delegate 17: -30
qml: Delegate 18: -30
qml: Delegate 19: -30
qml: Delegate 10: 70
qml: Delegate 11: 70
qml: Delegate 12: 70
qml: Delegate 13: 70
qml: Delegate 14: 70
qml: Delegate 15: 70
qml: Delegate 16: 70
qml: Delegate 17: 70
qml: Delegate 18: 70
qml: Delegate 1: 70
qml: Delegate 2: 70
qml: Delegate 3: 70
qml: Delegate 4: 70
qml: Delegate 5: 70
qml: Delegate 6: 70
qml: Delegate 7: 70
qml: Delegate 8: 70
qml: ListView: 560
qml: Delegate 9: 70
qml: Delegate 10: 70
qml: Delegate 11: 70
qml: Delegate 12: 70
</code></pre>
<p dir="auto"><strong>Case 2 widths</strong></p>
<pre><code>qml: Delegate 0: -30
qml: Delegate 1: -30
qml: Delegate 2: -30
qml: Delegate 3: -30
qml: Delegate 4: -30
qml: Delegate 5: -30
qml: Delegate 6: -30
qml: Delegate 7: -30
qml: Delegate 8: -30
qml: Delegate 9: -30
qml: Delegate 10: -30
qml: Delegate 11: -30
qml: Delegate 12: -30
qml: Delegate 13: -30
qml: Delegate 14: -30
qml: Delegate 15: -30
qml: Delegate 16: -30
qml: Delegate 17: -30
qml: Delegate 18: -30
qml: Delegate 19: -30
qml: ListView: 560
</code></pre>
]]></description><link>https://forum.qt.io/topic/139307/strange-listview-behaviour-depending-on-types-of-anchors</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 06:30:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139307.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Sep 2022 11:13:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 15:27:23 GMT]]></title><description><![CDATA[<p dir="auto">Reported: <a href="https://bugreports.qt.io/browse/QTBUG-106624" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-106624</a></p>
]]></description><link>https://forum.qt.io/post/728737</link><guid isPermaLink="true">https://forum.qt.io/post/728737</guid><dc:creator><![CDATA[paulmasri]]></dc:creator><pubDate>Wed, 14 Sep 2022 15:27:23 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 14:06:34 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk said in <a href="/post/728719">Strange ListView behaviour (depending on types of anchors)</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/paulmasri">@<bdi>paulmasri</bdi></a> ok!</p>
<p dir="auto">first of, there is a <code>}</code> missing but I was able to fix that! 😉</p>
</blockquote>
<p dir="auto">The <code>Component.onCompleted</code>. D'oh! My bad.</p>
<p dir="auto">And of course there needs to be an <code>import QtQuick</code> at the top for Qt 6.2. Or <code>import QtQuick 2.12</code> and <code>import QtQuick.Window 2.15</code> for Qt 5.X.</p>
<blockquote>
<p dir="auto">I get the following result:<br />
...</p>
</blockquote>
<p dir="auto">That's so weird. Here's my screenshot for the exact same code.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/721a4663-4287-4e58-88df-08bb698b0d1f.png" alt="Screenshot 2022-09-14 at 14.25.55.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">And in my console output, when it changes the delegates to 95, mine happened to do them in reverse order, not that that should have any impact.</p>
<p dir="auto">I think I'll log this as a bug.</p>
]]></description><link>https://forum.qt.io/post/728728</link><guid isPermaLink="true">https://forum.qt.io/post/728728</guid><dc:creator><![CDATA[paulmasri]]></dc:creator><pubDate>Wed, 14 Sep 2022 14:06:34 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 13:13:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/paulmasri">@<bdi>paulmasri</bdi></a> ok!</p>
<p dir="auto">first of, there is a <code>}</code> missing but I was able to fix that! 😉</p>
<p dir="auto">I get the following result:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/48556401-e0e3-4f17-b66e-f88af74229e7.png" alt="f47130cb-3a56-4a6f-90c1-9984a8a660af-image.png" class=" img-fluid img-markdown" /></p>
<pre><code>qml: Delegate 0: -5 changed
qml: Delegate 0: -5
qml: Delegate 1: -5 changed
qml: Delegate 1: -5
qml: Delegate 2: -5 changed
qml: Delegate 2: -5
qml: Delegate 3: -5 changed
qml: Delegate 3: -5
qml: Delegate 4: -5 changed
qml: Delegate 4: -5
qml: Delegate 5: -5 changed
qml: Delegate 5: -5
qml: Delegate 6: -5 changed
qml: Delegate 6: -5
qml: Delegate 7: -5 changed
qml: Delegate 7: -5
qml: Delegate 8: -5 changed
qml: Delegate 8: -5
qml: Delegate 9: -5 changed
qml: Delegate 9: -5
qml: Delegate 10: -5 changed
qml: Delegate 10: -5
qml: Delegate 11: -5 changed
qml: Delegate 11: -5
qml: Delegate 12: -5 changed
qml: Delegate 12: -5
qml: Delegate 13: -5 changed
qml: Delegate 13: -5
qml: Delegate 14: -5 changed
qml: Delegate 14: -5
qml: Delegate 15: -5 changed
qml: Delegate 15: -5
qml: Delegate 16: -5 changed
qml: Delegate 16: -5
qml: Delegate 17: -5 changed
qml: Delegate 17: -5
qml: Delegate 18: -5 changed
qml: Delegate 18: -5
qml: Delegate 19: -5 changed
qml: Delegate 19: -5
qml: Delegate 0: 95 changed
qml: Delegate 1: 95 changed
qml: Delegate 2: 95 changed
qml: Delegate 3: 95 changed
qml: Delegate 4: 95 changed
qml: Delegate 5: 95 changed
qml: Delegate 6: 95 changed
qml: Delegate 7: 95 changed
qml: Delegate 8: 95 changed
qml: Delegate 9: 95 changed
qml: Delegate 10: 95 changed
qml: Delegate 11: 95 changed
qml: Delegate 12: 95 changed
qml: Delegate 13: 95 changed
qml: Delegate 14: 95 changed
qml: Delegate 15: 95 changed
qml: Delegate 16: 95 changed
qml: Delegate 17: 95 changed
qml: Delegate 18: 95 changed
qml: Delegate 19: 95 changed
qml: ListView: 760
</code></pre>
]]></description><link>https://forum.qt.io/post/728719</link><guid isPermaLink="true">https://forum.qt.io/post/728719</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Wed, 14 Sep 2022 13:13:50 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 13:05:30 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk OK, the following is my minimal complete example. Please could you try the following:</p>
<p dir="auto"><strong>main.qml</strong></p>
<pre><code>Window { id: root
    width: 800
    height: 600
    visible: true

    Item { id: container
        anchors.left: parent.left
        anchors.top: parent.top
        width: parent.width - 40
        height: 200

        ListView { id: listview
            anchors.left: parent.left
            anchors.top: parent.top
            width: parent.width
            height: parent.height
            orientation: Qt.Horizontal

            model: 20
            delegate: Rectangle {
                width: listview.width / 8
                height: listview.height
                border.color: "lightblue"
                border.width: 1

                Text {
                    anchors.fill: parent
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    text: model.index
                }

                Component.onCompleted: console.log("Delegate "+model.index+": "+width)
                onWidthChanged: console.log("Delegate "+model.index+": "+width+" changed")
            }

            Component.onCompleted: { positionViewAtBeginning(); console.log("ListView: "+width)                 
        }
    }
}
</code></pre>
<p dir="auto">I've directly copy/pasted this so it should be error free.</p>
<p dir="auto">My odd scenario seems to be dependent on <em>all</em> of the following being in place:</p>
<ul>
<li>delegate width is an expression using ListView width</li>
<li>ListView sets left, top, width &amp; height (to match parent) instead of using <code>anchors.fill: parent</code></li>
<li>ListView sits within a container</li>
<li>The container width is an expression using <code>parent.width</code> (but not simply <code>: parent.width</code>)</li>
<li>The container width is a numerical value</li>
</ul>
<p dir="auto">That's a weird set of constraints. My suspicion now is that this triggers a long-standing bug, but it would be good to get this reproduced by someone else.</p>
]]></description><link>https://forum.qt.io/post/728713</link><guid isPermaLink="true">https://forum.qt.io/post/728713</guid><dc:creator><![CDATA[paulmasri]]></dc:creator><pubDate>Wed, 14 Sep 2022 13:05:30 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 11:58:05 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk said in <a href="/post/728688">Strange ListView behaviour (depending on types of anchors)</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/paulmasri">@<bdi>paulmasri</bdi></a> alright</p>
<p dir="auto">I tried your 2nd example</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/7baefff1-37e6-4f47-9be9-774057fadab0.png" alt="46591995-674b-4f68-b05e-eb29bcbd57a9-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">and it seems to be working perfectly fine ?</p>
<p dir="auto">do you have any runtime warnings in your program, that would indicate a property binding break?</p>
<p dir="auto">tried with Qt 5.15.10 on macOS</p>
</blockquote>
<p dir="auto">Strange. Thanks for checking that. I'm using Qt 6.2.3 on macOS with Apple clang version 13.0.0 (clang-1300.0.29.30), but I've had this issue previously when I was using Qt 5.9. (At the time I used a hack to get around it but I want to solve it properly now.)</p>
<p dir="auto">Let me try playing with the parent to see if I can get something you can reproduce.</p>
]]></description><link>https://forum.qt.io/post/728696</link><guid isPermaLink="true">https://forum.qt.io/post/728696</guid><dc:creator><![CDATA[paulmasri]]></dc:creator><pubDate>Wed, 14 Sep 2022 11:58:05 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 11:30:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/paulmasri">@<bdi>paulmasri</bdi></a> alright</p>
<p dir="auto">I tried your 2nd example</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/7baefff1-37e6-4f47-9be9-774057fadab0.png" alt="46591995-674b-4f68-b05e-eb29bcbd57a9-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">and it seems to be working perfectly fine ?</p>
<p dir="auto">do you have any runtime warnings in your program, that would indicate a property binding break?</p>
<p dir="auto">tried with Qt 5.15.10 on macOS</p>
]]></description><link>https://forum.qt.io/post/728688</link><guid isPermaLink="true">https://forum.qt.io/post/728688</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Wed, 14 Sep 2022 11:30:16 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 11:21:55 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk said in <a href="/post/728684">Strange ListView behaviour (depending on types of anchors)</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/paulmasri">@<bdi>paulmasri</bdi></a> said in <a href="/post/728682">Strange ListView behaviour (depending on types of anchors)</a>:</p>
<blockquote>
<p dir="auto">anchors.width: parent.width<br />
anchors.height: parent.height</p>
</blockquote>
<p dir="auto">there is no such thing as anchors.width or height, there's only  <code>left, horizontalCenter, right, top, verticalCenter, baseline, and bottom</code></p>
<p dir="auto">if this actually compiles/loads, than its probably undefined/ignored and your actual ListView has no width or height set. -&gt; it is 0 or derived from the content</p>
</blockquote>
<p dir="auto">Sorry that's a typo in my code above: I actually used <code>width: parent.width</code> and <code>height: parent.height</code>.</p>
<p dir="auto">Just corrected the OP.</p>
]]></description><link>https://forum.qt.io/post/728686</link><guid isPermaLink="true">https://forum.qt.io/post/728686</guid><dc:creator><![CDATA[paulmasri]]></dc:creator><pubDate>Wed, 14 Sep 2022 11:21:55 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 11:19:41 GMT]]></title><description><![CDATA[<p dir="auto">NB: If I make the Delegate width bind to an expression based on the width of the <em>parent of ListView</em>, then the behaviour is the same as if I had used a hardcoded number: all delegates instantly get the correct width (no initial setting to -30).</p>
]]></description><link>https://forum.qt.io/post/728685</link><guid isPermaLink="true">https://forum.qt.io/post/728685</guid><dc:creator><![CDATA[paulmasri]]></dc:creator><pubDate>Wed, 14 Sep 2022 11:19:41 GMT</pubDate></item><item><title><![CDATA[Reply to Strange ListView behaviour (depending on types of anchors) on Wed, 14 Sep 2022 11:18:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/paulmasri">@<bdi>paulmasri</bdi></a> said in <a href="/post/728682">Strange ListView behaviour (depending on types of anchors)</a>:</p>
<blockquote>
<p dir="auto">anchors.width: parent.width<br />
anchors.height: parent.height</p>
</blockquote>
<p dir="auto">there is no such thing as anchors.width or height, there's only  <code>left, horizontalCenter, right, top, verticalCenter, baseline, and bottom</code></p>
<p dir="auto">if this actually compiles/loads, than its probably undefined/ignored and your actual ListView has no width or height set. -&gt; it is 0 or derived from the content</p>
]]></description><link>https://forum.qt.io/post/728684</link><guid isPermaLink="true">https://forum.qt.io/post/728684</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Wed, 14 Sep 2022 11:18:52 GMT</pubDate></item></channel></rss>