Problems with ScrollBar and ListView

  • I have a couple of problems when customizing a ScrollBar in a ListView. The first problem I have is that the bar is only ever visible when I am either: hovering the bar or scrolling the list. This makes it a poor indicator to the user that there is more content available then they can currently see in the list.

    In order to get around this I customize the bar a bit like so:

        ScrollBar.vertical: ScrollBar
          height: parent.height
          width: 30
          policy: ScrollBar.AsNeeded
          contentItem: Rectangle
            color: themeManager.currentTheme.palette.highlightColor
            radius: 5
            opacity: 1
          rightPadding: 10

    This allows the bar to always be visible; however, that is a problem because I only want the bar to be visible when it is needed.

    So, if I set the visible property of the Rectangle like so:


    then it will only show up when it's needed but I am back to the original problem...

    Is there a way to have the bar be visible at all times when it is needed? Not just when I scroll the list or when I hover the bar but always but ONLY when it makes sense to actually have a scrollbar.

    Essentially, what I need to figure out is how this policy property works. That does seem to work correctly in that the scroll bar will only ever show up if it is needed but I can't set the visibility of my contentItem to be "parent.whenparentisneeded" now can I..

  • I figured it out. For anyone who's interested. If you set the visibility of the contentItem to be:

    visible: theListView.contentHeight > theListView.height

    that should do the trick.

Log in to reply