Qt QML 雙ListView同步滾動

Qt QML 雙ListView同步滾動

    ListView {
        id: roadView
        width: Screen.width
        height: 80
        anchors{
            bottom: listView.top
            bottomMargin: 10
        }
        orientation: ListView.Horizontal
        displayMarginBeginning: 3000
        displayMarginEnd: 3000

        Component {
            id: readDelegate
            RoadItem{
            }
        }

        model: roadModel
        delegate: readDelegate
        
        // 主要代碼
        ScrollBar.horizontal: ScrollBar {
            id: road_sb
            visible: false
        }
    }
    ListView {
        id: listView
        width: Screen.width
        height: 200
        anchors{
            left: parent.left
            bottom: parent.bottom
            right: parent.right
            bottomMargin: 20
            leftMargin: 10
            rightMargin: 10
        }
        spacing: 12
        clip: true
        orientation: ListView.Horizontal

        model: busNameList
        delegate: BusNameItem {}

        // 主要代碼
        ScrollBar.horizontal: ScrollBar {
            id: list_sb
            visible: false
            onPositionChanged: road_sb.position = position
        }

        onCurrentIndexChanged: {
            roadView.itemAtIndex(0).pos_index = currentIndex
        }
    }

當時做這個需求時,百度找遍沒找到,自己琢磨用這個方式實現出來了,這個方法有不足,但是可以實現。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章