Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML: Attach scrollbar to ListView

Tags:

listview

qt

qml

I'm having an issue with ListView. ListView is too long and part of it appears outside of the window but I can't attach a scrollbar. I tried many different combination. I think that problem lies in height parameter but if remove it ListView displays only first entry.

Column{
    anchors.fill: parent
    Row{
        id: buttonsRow
            Button{
                text: "Open dump file"
                onClicked: fileDialog.visible = true
            }
            Button{
                text: "Copy raw data to clipboard"
            }
    }
    ListView{
        id: listView
        anchors.top: buttonsRow.bottom
        height: contentHeight
        //clip: true
        flickableDirection: Flickable.VerticalFlick
        boundsBehavior: Flickable.StopAtBounds
        interactive: true
        model: ListModel{
            id: listModel
        }
        delegate: MDelegate{}
    }
}

Is there any way to make it scrollable?

like image 204
Marzanna Avatar asked Aug 12 '17 12:08

Marzanna


1 Answers

I don't see, in the code you posted, where you've attached a scrollbar at all. You need to actually include a ScrollBar component in your ListView, like this:

    ListView { 
        id: listView
        ScrollBar.vertical: ScrollBar {
        active: true
        }
    }

See "Attaching ScrollBar to a Flickable" at https://doc.qt.io/qt-5/qml-qtquick-controls2-scrollbar.html

like image 89
WaltPurvis Avatar answered Sep 19 '22 11:09

WaltPurvis