首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使Qt5 QML水平列表视图启用鼠标滚动?

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

Stack Overflow用户
提问于 2020-05-19 18:49:59
回答 1查看 159关注 0票数 0

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

代码语言:javascript
复制
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{}
                }
            }
        }

    }
}
EN

回答 1

Stack Overflow用户

发布于 2020-05-19 19:06:29

我找到了解决方案:

代码语言:javascript
复制
                    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()
                        }
                    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61889210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档