我创建了一个QML Horizoltal Listview,但不知道如何通过鼠标滚动来启用水平滚动。请帮帮忙。谢谢!
import Felgo 3.0
import QtQuick 2.0
import QtQuick.Layouts 1.13
import QtQuick.Controls 2.5
App {
NavigationStack {
Page {
title: qsTr("Main Page")
anchors.fill: parent
Rectangle {
anchors.centerIn: parent
color: "green"
height: 66
width: 333
Flickable {
id: listController
anchors.fill: parent
// contentHeight: vert.contentHeight
// contentWidth: horizontalElement.width
}
ListView {
orientation: ListView.Horizontal
clip: true
contentY: listController.contentX
spacing: 16
anchors.fill: parent
interactive: true
focus: true
delegate: Rectangle {
color: Qt.rgba(Math.random(),Math.random(),Math.random(),1);
width: 244
height: 66
radius: 14
}
model: 30
Layout.fillWidth: true
Layout.fillHeight: true
ScrollBar.horizontal: ScrollBar{}
ScrollBar.vertical: ScrollBar{}
}
}
}
}
}发布于 2020-05-19 19:06:29
我找到了解决方案:
ScrollBar.horizontal: ScrollBar{
id: scroll
orientation: Qt.Vertical
}
// ScrollBar.vertical: ScrollBar{}
MouseArea {
anchors.fill: parent
onWheel: {
if (wheel.angleDelta.y > 0) scroll.increase()
else scroll.decrease()
}
}https://stackoverflow.com/questions/61889210
复制相似问题