我想知道如何通过按住Qt / QML中的MouseArea来移动窗口. 您可以将视图窗口小部件公开给QML: QmlApplicationViewer viewer;QDeclarativeContext *context = viewer.rootContext();context-setContextProperty("viewerWidget"
QmlApplicationViewer viewer; QDeclarativeContext *context = viewer.rootContext(); context->setContextProperty("viewerWidget", &viewer);
然后修改其pos属性以移动窗口:
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) } } }