Using QML 5.15, a ScrollView with a custom ScrollBar will not hide the default scrollbar. See image, the white dot upper right. How can this be solved?
The source:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
Window {
id: window
width: 640
height: 480
visible: true
title: qsTr("Hello ScrolView and ScrollBar")
color: "blue"
ScrollView {
id: scroll_view
width: parent.width - 40
height: parent.height
TextInput {
id: text_input
anchors.fill: parent
text: "A very large text but this will be enough to get the picture."
color: "white"
readOnly: true
selectByMouse: true
width: parent.width
height: parent.height
}
ScrollBar.vertical: ScrollBar {
policy: "AlwaysOn"
parent: scroll_view
x: text_input.width
width: 20
height: scroll_view.availableHeight
}
}
}
Using policy AlwaysOff hides the custom scrollbar but not the default scrollbar.


Unlike other components (e.g.
Flickable,ListView)ScrollViewhas an instantiatedScrollBaralready assigned toScrollBar.vertical. Rather than attempting to replace it with a newScrollBar, you should merely customize the one that's already there. i.e. instead ofdo
Because you're customizing the existing one, you do not need to set
parentandheighteither.