1

我想在移动光标时按住鼠标按钮来禁用我的列表视图的拖动。我正在尝试使用此命令实现一些其他功能,例如多项选择。我只想启用滚动。flickable交互属性完全禁用了视图的移动。有一些解决方法吗?

4

1 回答 1

1

我想有一些方法可以实现您所需要的,但以下解决方案有效。

这个想法是有一个MouseArea并将interactive属性设置为何false时发出信号onPressedonClickedinteractive应该true在处理程序中再次设置为onReleased

import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.4

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    ListModel {
        id: listModel
        ListElement {
            name: "ttt"
            number: "111"
        }
        ListElement {
            name: "rrr"
            number: "222"
        }
        ListElement {
            name: "sss"
            number: "333"
        }
        ListElement {
            name: "xxx"
            number: "444"
        }
        ListElement {
            name: "yyy"
            number: "555"
        }
        ListElement {
            name: "zzz"
            number: "666"
        }
        ListElement {
            name: "aaa"
            number: "777"
        }
        ListElement {
            name: "bbb"
            number: "888"
        }
        ListElement {
            name: "ccc"
            number: "999"
        }
        ListElement {
            name: "ddd"
            number: "011"
        }
        ListElement {
            name: "eee"
            number: "022"
        }
        ListElement {
            name: "fff"
            number: "033"
        }
    }

    ListView {
        id: myList
        width: 180; height: 100
        clip: true

        Component {
            id: contactsDelegate
            Rectangle {
                id: wrapper
                width: 180
                height: contactInfo.height
                color: "lightblue"

                Text {
                    id: contactInfo
                    text: name + ": " + number
                    color: "black"
                }

                MouseArea {
                    anchors.fill: parent
                    onPressed: {
                        myList.interactive = false
                        console.debug("onPressed")
                    }

                    onClicked:  {
                        myList.interactive = false
                        console.debug("onClicked")
                    }

                    onReleased: {
                        myList.interactive = true
                        console.debug("onReleased")
                    }
                }
            }
        }

        model: listModel
        delegate: contactsDelegate
        focus: true
    }
}
于 2016-06-27T12:38:14.887 回答