I want to know how to move the window by press and holding the MouseArea in Qt/QML.
You can expose the view widget to QML with:
QmlApplicationViewer viewer;
QDeclarativeContext *context = viewer.rootContext();
context->setContextProperty("viewerWidget", &viewer);
Then modify its pos
property to move the window:
MouseArea {
anchors.fill: parent
property variant previousPosition
onPressed: {
previousPosition = Qt.point(mouseX, mouseY)
}
onPositionChanged: {
if (pressedButtons == Qt.LeftButton) {
var dx = mouseX - previousPosition.x
var dy = mouseY - previousPosition.y
viewerWidget.pos = Qt.point(viewerWidget.pos.x + dx,
viewerWidget.pos.y + dy)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With