ScrollView
clips all its contents to its size. Is it possible to make it work only for top and bottom but allow children to go out of parent's frame on the right and on the left?
How to make ScrollView clip only vertically?
3k views Asked by Rinat Veliakhmedov At
2
There are 2 answers
0
On
If what you want is to only scroll in one direction, then just set the width/height of the content item to the width/height of the ScrollView, using property bindings (because items inside ScrollView are reparented to ScrollView.contentItem). The below example will scroll only vertically. I've tested it, if you need confirmation that it actually works.
Item {
ScrollView {
id: scrollview1
anchors.fill: parent
anchors.margins: 20
clip: true
ColumnLayout {
width: scrollview1.width
}
}
}
I can only imagine one reason, why you don't set the
ScrollView
's width to a higher value (thecontentItem
's width).To be able to do so, while not constraining the
ScrollView
in it's width, you can use a simple trick:You'll wrap it in the
Item
, anchor to this, and you'll be good. Alternatively you could use masks, but this would be... more complicated.Per se it is not possible to clip only horizontal or vertical, as the clipping is done using the
Item
's bounding box.