From 78966dc00419a4f5fe5fec4725062a4a0f380228 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 5 Jul 2015 15:11:13 +0200 Subject: Embedded QML into C++ application --- qml/ScrollBar.qml | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 qml/ScrollBar.qml (limited to 'qml/ScrollBar.qml') diff --git a/qml/ScrollBar.qml b/qml/ScrollBar.qml new file mode 100644 index 0000000..18f149c --- /dev/null +++ b/qml/ScrollBar.qml @@ -0,0 +1,78 @@ +import QtQuick 2.0; + +Item { + id: scrollbar + width: (handleSize + 2) + visible: (flickable.visibleArea.heightRatio < 1.0) + + anchors { + top: flickable.top + right: flickable.right + bottom: flickable.bottom + } + + property Flickable flickable + property int handleSize + + Item { + id: bar + + anchors.fill: parent + + Rectangle { + anchors.fill: parent + color: "black" + opacity: 0.5 + } + + MouseArea { + id: control + anchors.fill: parent + + drag { + target: handle + minimumY: 0 + maximumY: (bar.height - handle.height) + axis: Drag.YAxis + } + + onClicked: { + flickable.contentY = (mouse.y / bar.height * (flickable.contentHeight - flickable.height)); + } + } + + Item { + id: handle; + height: Math.max(20, (flickable.visibleArea.heightRatio * bar.height)) + + anchors { + left: parent.left + right: parent.right + } + + Rectangle { + id: backHandle + anchors { + fill: parent + margins: 1 + } + + color: (control.pressed ? "gray" : "white") + } + } + } + + Binding { + target: handle + property: "y" + value: (flickable.contentY * control.drag.maximumY / (flickable.contentHeight - flickable.height)) + when: (!control.drag.active) + } + + Binding { + target: flickable + property: "contentY" + value: (handle.y * (flickable.contentHeight - flickable.height) / control.drag.maximumY) + when: (control.drag.active || control.pressed) + } +} -- cgit v1.2.3