Как сделать так, чтобы первый элемент списка был всегда виден при прокрутке списка? - PullRequest
0 голосов
/ 24 мая 2019

в моем коде у меня есть ListView из 16 элементов, я хочу, чтобы при прокрутке списка первый элемент всегда был виден. Как я могу это сделать?

ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480


    ListView {
        id:listview
        anchors.fill: parent
        model: 16
        verticalLayoutDirection: ListView.BottomToTop
        delegate: Rectangle {
            height: listview.height/5
            width: listview.width
            color: Qt.rgba(Math.random(),Math.random(),Math.random(),1)
            Text {
               text: index
               anchors.fill: parent
               horizontalAlignment: Text.AlignHCenter
               verticalAlignment: Text.AlignVCenter
               color: "white"
               font.pixelSize: 35
            }
       }
    }
}

1 Ответ

1 голос
/ 24 мая 2019

вы можете использовать заголовок.Ваш код будет выглядеть примерно так:

ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480


    ListView {
        id:listview
        anchors.fill: parent
        model: 15
        verticalLayoutDirection: ListView.BottomToTop

        headerPositioning: ListView.OverlayHeader

        header: Rectangle {
            height: listview.height/5
            width: listview.width
            color: Qt.rgba(Math.random(),Math.random(),Math.random(),1)
            z:2
            Text {
               text: "0"
               anchors.fill: parent
               horizontalAlignment: Text.AlignHCenter
               verticalAlignment: Text.AlignVCenter
               color: "white"
               font.pixelSize: 35
            }
        }

        delegate: Rectangle {
            height: listview.height/5
            width: listview.width
            color: Qt.rgba(Math.random(),Math.random(),Math.random(),1)
            Text {
               text: index+1
               anchors.fill: parent
               horizontalAlignment: Text.AlignHCenter
               verticalAlignment: Text.AlignVCenter
               color: "white"
               font.pixelSize: 35
            }
       }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...