Ryou
Ryou

Reputation: 285

How can i change the location of scrollBar of ListView in Qml

I have created a ListView with a scrollBar. Like this

enter image description here

Here is my code,

ListView {
    id: listView;
    ScrollBar.vertical: ScrollBar {
        id: bar
        //x :100 doesn't work
        active: true

      }
    }

In my case, i want to reset the location of the scrollbar. For example,move the scrollbar to the right by 5 pixels more. I tried to set "x:" , but didn't work. How can i solve my problem.

Upvotes: 6

Views: 3722

Answers (2)

augre
augre

Reputation: 2051

You can move the ScrollBar outside of the ListView and reference it inside the ListView with its id:

ListView {
    id: listView
    ScrollBar.vertical: bar
}

ScrollBar {
    id: bar
    active: true
    anchors {
        left: listView.left
        top: listView.top
        bottom: listView.bottom
        leftMargin: 100
    }
}

Upvotes: 5

eyllanesc
eyllanesc

Reputation: 243955

You have to establish that property a moment after loading the ScrollBar since the ListView sets it to the default position.

ScrollBar.vertical: ScrollBar {
    id: sb
    active: true
    Component.onCompleted: x = 100
}

enter image description here

Upvotes: 4

Related Questions