我已经尝试了Stackoverflow上的几乎所有解决方案,但都没有起作用?
有哪些改变可以让水平滚动条工作?
我也查看了qt文档,但仍然无法正常工作。请提供一些示例。我只需要在listview中实现水平滚动,或其他视图也可以。
main.qml
Rectangle {
id: frame
width: 300
height: 300
anchors.top: meaning.bottom
ListView {
width: 300
height: 300
anchors.centerIn: parent
id: myList
model: myModel
highlight: highlightBar
clip: true
snapMode: ListView.SnapToItem
headerPositioning: ListView.OverlayHeader
header: Rectangle {
id: headerItem
width: myList.width
height: 30
z: 2
color: "gray"
Text {
text: "Simple Text List"
color: "white"
}
}
delegate: Item {
id: delegateItem
width: 400
height: 20
Text {
text: name
}
MouseArea {
id: mArea
anchors.fill: parent
onClicked: {
myList.currentIndex = index
}
}
}
}
Component {
id: highlightBar
Rectangle {
width: parent.width
height: 20
color: "#FFFF88"
}
}
ListModel {
id: myModel
}
ScrollBar {
id: vbar
hoverEnabled: true
active: hovered || pressed
orientation: Qt.Vertical
size: frame.height / content.height
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
}
ScrollBar {
id: hbar
hoverEnabled: true
active: hovered || pressed
orientation: Qt.Horizontal
size: frame.width / content.width
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
}
}
请修改这个代码,使得水平滚动能够正常工作。 谢谢。
ListView
外面,应该在里面。否则你会滚动Rectangle
而不是ListView
。 - folibis