<?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[QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style]]></title><description><![CDATA[<p dir="auto">Hi everyone,</p>
<p dir="auto">I am working with Qt 6.9.3 and customizing a ScrollBar using the QtQuick.Controls.Basic style. I have encountered an issue where the ScrollBar.AsNeeded policy does not work as expected when attached to a ListView.When the ListView is completely empty (or content fits within bounds), the scroll handle/thumb correctly hides, but the custom background track remains permanently visible on the screen. If I switch back to the default QtQuick.Controls style without customization, the AsNeeded policy works perfectly.</p>
<p dir="auto">Here is the custom ScrollBar implementation I am using in a standalone file:</p>
<pre><code>// CustomScrollBar.qml
import QtQuick
import QtQuick.Controls.Basic

ScrollBar {
    id: control
    policy: ScrollBar.AsNeeded
    minimumSize: 0.1
    hoverEnabled: false

    contentItem: Rectangle {
        implicitWidth: 10
        implicitHeight: 10
        color: control.pressed ? "#444" : "#888"
        // Handle correctly tracks active/size states
        visible: control.policy === ScrollBar.AlwaysOn || (control.active &amp;&amp; control.size &lt; 1.0)
    }

    background: Rectangle {
        implicitWidth: control.implicitWidth
        color: "#E0E0E0"
        // This background remains visible even when ListView is empty (control.size == 1.0)
    }
}

</code></pre>
<p dir="auto">And how it is attached:</p>
<pre><code>ListView {
    id: listView
    Layout.fillHeight: true
    Layout.fillWidth: true
    clip: true
    model: 0 // Empty for testing

    ScrollBar.vertical: CustomScrollBar {
        anchors.right: listView.right
    }
}
</code></pre>
<p dir="auto">Is there a specific internal property or visibility binding for the <strong>background</strong> item in the <strong>Basic</strong> style template that I need to manually handle to make it respect the <strong>AsNeeded</strong> policy when the view has no overflow?</p>
<p dir="auto">Thanks for your help!</p>
]]></description><link>https://forum.qt.io/topic/164941/qml-scrollbar.asneeded-background-track-always-visible-on-empty-listview-when-using-basic-style</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 23:30:22 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164941.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Jul 2026 08:05:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style on Sat, 01 Aug 2026 10:19:43 GMT]]></title><description><![CDATA[<p dir="auto">Its working now. Thanks! <a class="plugin-mentions-user plugin-mentions-a" href="/user/nils-sjoberg">@<bdi>Nils-Sjoberg</bdi></a></p>
]]></description><link>https://forum.qt.io/post/839492</link><guid isPermaLink="true">https://forum.qt.io/post/839492</guid><dc:creator><![CDATA[Gary90]]></dc:creator><pubDate>Sat, 01 Aug 2026 10:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style on Thu, 30 Jul 2026 16:51:06 GMT]]></title><description><![CDATA[<p dir="auto">Remove control.active &amp;&amp; from the condition.</p>
]]></description><link>https://forum.qt.io/post/839462</link><guid isPermaLink="true">https://forum.qt.io/post/839462</guid><dc:creator><![CDATA[Nils Sjoberg]]></dc:creator><pubDate>Thu, 30 Jul 2026 16:51:06 GMT</pubDate></item><item><title><![CDATA[Reply to QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style on Thu, 30 Jul 2026 16:13:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gary90">@<bdi>Gary90</bdi></a> said in <a href="/post/839451">QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style</a>:</p>
<blockquote>
<p dir="auto">Thanks for the answer, <a class="plugin-mentions-user plugin-mentions-a" href="/user/nils-sjoberg">@<bdi>Nils-Sjoberg</bdi></a> , but unfortunately, that solution didn't work.</p>
<p dir="auto">When I add the visibility logic directly to the background property in</p>
<p dir="auto">CustomScrollBar.qml (visible: control.policy === ScrollBar.AlwaysOn || (control.active &amp;&amp; control.size &lt; 1.0)),</p>
<p dir="auto">the scrollbar appearing only when scrolling overflowing items. But the scrollbar is not visible when items are overflowing the list without scrolling.</p>
<p dir="auto">However, according to QML specifications, we shouldn't need to manually override the background's visible property to get standard policy behavior.</p>
</blockquote>
<pre><code>background: Rectangle {
    implicitWidth: control.implicitWidth
    color: "#E0E0E0"
    visible: control.policy === ScrollBar.AlwaysOn || control.size &lt; 1.0
}
</code></pre>
]]></description><link>https://forum.qt.io/post/839460</link><guid isPermaLink="true">https://forum.qt.io/post/839460</guid><dc:creator><![CDATA[Nils Sjoberg]]></dc:creator><pubDate>Thu, 30 Jul 2026 16:13:19 GMT</pubDate></item><item><title><![CDATA[Reply to QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style on Thu, 30 Jul 2026 06:14:07 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the answer, <a class="plugin-mentions-user plugin-mentions-a" href="/user/nils-sjoberg">@<bdi>Nils-Sjoberg</bdi></a> , but unfortunately, that solution didn't work.</p>
<p dir="auto">When I add the visibility logic directly to the background property in</p>
<p dir="auto">CustomScrollBar.qml (visible: control.policy === ScrollBar.AlwaysOn || (control.active &amp;&amp; control.size &lt; 1.0)),</p>
<p dir="auto">the scrollbar appearing only when scrolling overflowing items. But the scrollbar is not visible when items are overflowing the list without scrolling.</p>
<p dir="auto">However, according to QML specifications, we shouldn't need to manually override the background's visible property to get standard policy behavior.</p>
]]></description><link>https://forum.qt.io/post/839451</link><guid isPermaLink="true">https://forum.qt.io/post/839451</guid><dc:creator><![CDATA[Gary90]]></dc:creator><pubDate>Thu, 30 Jul 2026 06:14:07 GMT</pubDate></item><item><title><![CDATA[Reply to QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style on Wed, 29 Jul 2026 18:47:53 GMT]]></title><description><![CDATA[<p dir="auto">Add a similar visible property to the background element inside your CustomScrollBar.qml.</p>
]]></description><link>https://forum.qt.io/post/839449</link><guid isPermaLink="true">https://forum.qt.io/post/839449</guid><dc:creator><![CDATA[Nils Sjoberg]]></dc:creator><pubDate>Wed, 29 Jul 2026 18:47:53 GMT</pubDate></item></channel></rss>