【发布时间】:2020-09-15 17:02:16
【问题描述】:
目前尚不清楚如何设置 QML ScrollView 的样式。
我希望 ScrollView 具有以下样式,但将错误 style 作为无效属性。
import QtQuick 2.0
import QtQuick.Controls 2.14
import QtQuick.Controls.Styles 1.4
ScrollView {
style: ScrollViewStyle {
handle: Rectangle {
implicitWidth: 50
implicitHeight: 30
color: "red"
}
scrollBarBackground: Rectangle {
implicitWidth: 50
implicitHeight: 30
color: "black"
}
decrementControl: Rectangle {
implicitWidth: 50
implicitHeight: 30
color: "green"
}
incrementControl: Rectangle {
implicitWidth: 50
implicitHeight: 30
color: "blue"
}
}
//...
}
更新:
import QtQuick 2.0
import QtQuick.Controls 2.14
ScrollView {
id: myScrollView
width: 700
height: parent.height
clip: true
ScrollBar.vertical: ScrollBar {
id: scrollBar
parent: myScrollView.parent
policy: ScrollBar.AlwaysOn
anchors.top: myScrollView.top
anchors.left: myScrollView.right
anchors.bottom: myScrollView.bottom
height: myScrollView.availableHeight
contentItem: Rectangle {
implicitWidth: 16
implicitHeight: 10
anchors.leftMargin: 10
radius: 16
color: "blue"
}
}
ListView {
id: myListView
anchors.fill: parent
.... Rest of the code ....
通过上面的代码,我可以获得垂直滚动条的样式,但是通过这段代码,我看到了两个滚动条。一种是浅灰色的,尺寸很小,一种是蓝色的,按照上面的样式。
蓝色滚动条的高度也不符合样式。
【问题讨论】: