如何在QML无窗口应用程序中设置拖放区域
How to set the drag area in qml windowless application
我的问题是我如何设置在没有窗口的情况下拖动应用程序我看到了许多可以在台式机上拖动鼠标的应用程序。我的应用使用QML,因此任何可能的方法都可以获得这项工作。
取您的MouseArea::positionChanged
信号并使用位置delta(您必须在每个调用上保存最后一个位置,以便您可以计算Delta)以更新您的Window::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;
}
}
}
相关文章:
- 在组合框中拖放项目
- wxWidgets 拖放文件事件处理程序初始化问题(无效static_cast)
- 拖放我的MDI被CRichEditView拦截并在CRichEditView::GetDocument中崩溃 - 如何覆
- 在特定区域拖放 | Qt
- Qt - 在QGraphicScene中拖放时如何从项目中获取文本?
- Qt 模型拖放 - 无法保存类型 QJsonValue
- 如何在 2 个应用程序之间实现拖放?
- 在拖放 QML 列表中插入/删除项目使用 cpp 模型查看
- UI具有拖放功能
- 如何使用拖放功能和点击信号函数QT创建标签
- 使用MFC在对话框上拖放文件
- QListWidget通过setItemWidget使用自定义小部件集进行拖放
- 将拖放连接到QListWidget中的函数的最佳方法
- QTextEdit-根据QCursor位置进行条件拖放
- 如果使用Qt::DecorationRole,则在拖放时崩溃
- 用代码模拟窗口拖放
- Ole 拖放故障排除
- 基于文本的角色扮演游戏拖放和保留物品功能
- 拖放C++在拖放之前操作 Outlook 文件
- 如何在QML无窗口应用程序中设置拖放区域