qt quick - Bounds of Flickable.contentY in QML -
what correct way of asking bounds of flickable.contenty? need scrollbar.
experimentally have discovered
offsety <= contenty <= offsety + contentheight - height
where offsety can calculated as
var offsety = contenty-math.round(visiblearea.yposition*contentheight)
offsety 0 @ start of application , seems constant unless flickable resized.
this formula works in general, there should dedicated function it.
i did scrollbar without offset :
// scrollbar.qml import qtquick 2.0 rectangle { id: scrollbar; color: "#3c3c3c"; visible: (flicker.visiblearea.heightratio < 1.0); property flickable flicker : null; width: 20; anchors { top: flicker.top; right: flicker.right; bottom: flicker.bottom; } rectangle { id: handle; height: (scrollbar.height * flicker.visiblearea.heightratio); color: "#5e5e5e"; border { width: 1; color: "white"; } anchors { left: parent.left; right: parent.right; } binding { // calculate handle's x/y position based on content position of flickable target: handle; property: "y"; value: (flicker.visiblearea.yposition * scrollbar.height); when: (!dragger.drag.active); } binding { // calculate flickable content position based on handle x/y position target: flicker; property: "contenty"; value: (handle.y / scrollbar.height * flicker.contentheight); when: (dragger.drag.active); } mousearea { id: dragger; anchors.fill: parent; drag { target: handle; minimumx: handle.x; maximumx: handle.x; minimumy: 0; maximumy: (scrollbar.height - handle.height); axis: drag.yaxis; } } } }
just use :
flickable { id: myflick; } scrollbar { flicker: myflick; }
it can moved mouse, , moves automatically when flickable scrolled.
Comments
Post a Comment