5
Tôi muốn biết cách di chuyển cửa sổ bằng cách nhấn và giữ MouseArea trong Qt/QML.Di chuyển cửa sổ đang giữ Qml MouseArea
Tôi muốn biết cách di chuyển cửa sổ bằng cách nhấn và giữ MouseArea trong Qt/QML.Di chuyển cửa sổ đang giữ Qml MouseArea
Bạn có thể tiếp xúc với các widget nhằm QML với:
QmlApplicationViewer viewer;
QDeclarativeContext *context = viewer.rootContext();
context->setContextProperty("viewerWidget", &viewer);
Sau đó, thay đổi thuộc tính của nó pos
để di chuyển cửa sổ:
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)
}
}
}
Bạn có thể thay đổi 'biến thể sở hữu previousPosition' một cái gì đó như 'tài sản point clickPos: Qt.point (1, 1) '. – troyane