繁体   English   中英

如何使 Qt5 QML 水平列表视图启用鼠标滚动?

[英]How to make Qt5 QML Horizontal Listview enable mouse scroll?

我创建了一个 QML 水平列表视图,但不知道如何通过鼠标滚动启用水平滚动。 请帮忙。 谢谢!

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{}
                }
            }
        }

    }
}

我找到了解决方案:

                    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()
                        }
                    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM