我有一个QQuickWidget
内部主窗口。这似乎有效,但是,拖动时它会剧烈摇晃。
//main.qml
Rectangle{
id: root
property point dragStart
signal moved(point offset)
MouseArea{
id: dragArea
anchors.fill: parent
onPressed: root.dragStart = Qt.point(dragArea.mouseX,dragArea.mouseY)
onMouseXChanged: move()
onMouseYChanged: move()
function move(){
var offset = Qt.point(dragArea.mouseX-root.dragStart.x, dragArea.mouseY-root.dragStart.y)
root.moved(offset)
console.log(offset)
}
}
}
//MainWindow.cpp
void MainWindow::moveQml(QPointF offset){
ui->quickWidget->move(ui->quickWidget->pos()+offset.toPoint());
}
这是我只拖到左下角时的调试输出,该点不应该有正 x:
qml: QPointF(6, 2)
qml: QPointF(6, 2)
qml: QPointF(-6, -1)
qml: QPointF(-6, -1)
qml: QPointF(5, 1)
qml: QPointF(5, 1)
qml: QPointF(-5, 0)
qml: QPointF(-5, 0)
qml: QPointF(4, 0)
qml: QPointF(4, 0)
qml: QPointF(-5, 1)
qml: QPointF(- 5、1)