Last active
October 9, 2021 10:41
-
-
Save mitchcurtis/fb80626bf4477b0c7483ea617ce3a1c1 to your computer and use it in GitHub Desktop.
Scene that can be dragged with middle mouse button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick | |
import QtQuick.Window | |
import Qt.labs.animation | |
Window { | |
width: 640 | |
height: 480 | |
visible: true | |
title: qsTr("Test") | |
// Useful to be able to give this margins and see if everything is rendered as we expect it. | |
Item { | |
id: viewport | |
anchors.fill: parent | |
anchors.margins: 100 | |
Rectangle { | |
anchors.fill: parent | |
color: "transparent" | |
border.color: "darkorange" | |
z: 1000 | |
} | |
Item { | |
id: scene | |
width: 2000 | |
height: 400 | |
Rectangle { | |
anchors.fill: parent | |
color: "steelblue" | |
} | |
Rectangle { | |
y: parent.height - height | |
color: "brown" | |
width: parent.width | |
height: 128 | |
} | |
DragHandler { | |
acceptedButtons: Qt.MiddleButton | |
} | |
BoundaryRule on x { | |
minimum: -scene.width + Math.min(scene.width, viewport.width) | |
maximum: viewport.width - scene.width > 0 ? viewport.width - scene.width : 0 | |
} | |
BoundaryRule on y { | |
minimum: -scene.height + Math.min(scene.height, viewport.height) | |
maximum: viewport.height - scene.height > 0 ? viewport.height - scene.height : 0 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment