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. QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style
Qt 6.11 is out! See what's new in the release blog

QML ScrollBar.AsNeeded background track always visible on empty ListView when using Basic style

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqtquickscrollbarqt6.9.3
3 Posts 2 Posters 85 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
    Gary90
    wrote last edited by
    #1

    Hi everyone,

    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.

    Here is the custom ScrollBar implementation I am using in a standalone file:

    // 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 && control.size < 1.0)
        }
    
        background: Rectangle {
            implicitWidth: control.implicitWidth
            color: "#E0E0E0"
            // This background remains visible even when ListView is empty (control.size == 1.0)
        }
    }
    
    

    And how it is attached:

    ListView {
        id: listView
        Layout.fillHeight: true
        Layout.fillWidth: true
        clip: true
        model: 0 // Empty for testing
    
        ScrollBar.vertical: CustomScrollBar {
            anchors.right: listView.right
        }
    }
    

    Is there a specific internal property or visibility binding for the background item in the Basic style template that I need to manually handle to make it respect the AsNeeded policy when the view has no overflow?

    Thanks for your help!

    1 Reply Last reply
    0
    • Nils SjobergN Offline
      Nils SjobergN Offline
      Nils Sjoberg
      wrote last edited by
      #2

      Add a similar visible property to the background element inside your CustomScrollBar.qml.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gary90
        wrote last edited by
        #3

        Thanks for the answer, @Nils-Sjoberg , but unfortunately, that solution didn't work.

        When I add the visibility logic directly to the background property in

        CustomScrollBar.qml (visible: control.policy === ScrollBar.AlwaysOn || (control.active && control.size < 1.0)),

        the scrollbar appearing only when scrolling overflowing items. But the scrollbar is not visible when items are overflowing the list without scrolling.

        However, according to QML specifications, we shouldn't need to manually override the background's visible property to get standard policy behavior.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved