qml 两个listview一起上下滑动



Window {
    width: 400
    height: 400
    visible: true


    ListModel {
        id: myModel
        ListElement { name: "Item A"; flag: 1 }
        ListElement { name: "Item B"; flag: 0 }
        ListElement { name: "Item C"; flag: 1 }
        ListElement { name: "Item D"; flag: 0 }
        ListElement { name: "Item E"; flag: 1 }
    }

    Flickable {
        width: parent.width
        height: parent.height
        contentHeight: view1.height + view2.height
        flickableDirection: Flickable.VerticalFlick
        clip: true

        ListView {
            id: view1
            width: parent.width
            height: contentHeight
            model: myModel
            interactive: false
            delegate: Text {
                text: name
                height: visible ? 20 : 0
                visible: flag==1
            }
        }

        ListView {
            id: view2
            width: parent.width
            height: contentHeight
            anchors.top: view1.bottom
            model: myModel
            interactive: false
            delegate: Text {
                text: name
                height: visible ? 20 : 0
                visible: flag == 0
            }
        }
    }
}


你可能感兴趣的:(qt)