使用QML 5.15,带有自定义ScrollBar的ScrollView不会隐藏默认滚动条。参见图片,右上角的白点。怎么解决这个问题?
来源:
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
}
}
}
使用策略AlwaysOff隐藏自定义滚动条,但不隐藏默认滚动条。
对于
ScrollView
,您不需要实例化一个新的ScrollBar
,对于ScrollBar.vertical
,已经有一个,即代替
ScrollBar.vertical: ScrollBar {
做
ScrollBar.vertical {