Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qt

qt5

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.

like image 979
Ryou Avatar asked Mar 06 '23 16:03

Ryou


2 Answers

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
    }
}
like image 56
augre Avatar answered Mar 23 '23 11:03

augre


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

like image 40
eyllanesc Avatar answered Mar 23 '23 13:03

eyllanesc