我的问题是如何设置在没有窗口装饰的情况下拖动应用程序 我见过很多可以用鼠标在桌面上拖动的应用程序。我的应用程序使用 Qml,所以任何可能的方法都可以完成这项工作,谢谢。
最佳答案
获取您的 MouseArea::positionChanged
信号并使用位置增量(您必须在每次调用时保存最后一个位置以便计算增量)来更新您的 窗口: :x
和 y
属性。
Window {
id: win
width: 200
height: 200
MouseArea {
anchors.fill: parent
property int lastX
property int lastY
onPositionChanged: {
// Remap the mouse coords back to the window. Not
// necessary in this example, but will be in 'real'
// use.
var mPos = mapToItem( null, mouse.x, mouse.y );
mPos.x += win.x;
mPos.y += win.y;
// Skip the first iteration by testing if the properties
// are defined, otherwise the window will jump.
if ( lastX && lastY ) {
win.x += mPos.x - lastX;
win.y += mPos.y - lastY;
}
lastX = mPos.x;
lastY = mPos.y;
}
}
}
关于c++ - qml无窗应用中如何设置拖拽区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148155/