gpt4 book ai didi

c++ - qml无窗应用中如何设置拖拽区域

转载 作者:行者123 更新时间:2023-11-30 05:43:34 24 4
gpt4 key购买 nike

我的问题是如何设置在没有窗口装饰的情况下拖动应用程序我见过很多可以用鼠标在桌面上拖动的应用程序。我的应用程序使用 Qml,所以任何可能的方法都可以完成这项工作,谢谢。

最佳答案

获取您的 MouseArea::positionChanged 信号并使用位置增量(您必须在每次调用时保存最后一个位置以便计算增量)来更新您的 窗口: :xy 属性。

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com