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

标签 c++ qt qml

我的问题是如何设置在没有窗口装饰的情况下拖动应用程序 我见过很多可以用鼠标在桌面上拖动的应用程序。我的应用程序使用 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/

相关文章:

c++ - QML/C++ 编译错误

qt - 从 Qt 5.3 代码中的任何位置获取 QML 根对象

c++ - 在Qml中创建新文件夹

c++ - 在禁用所有编译器优化的情况下使用 volatile

c++ - 如何让 Foo* 迭代器指向 Foo 的 vector ?

c++ - 全局对象和创建顺序

cocoa - OpenStep作为开发环境的最新情况如何?

c++ - 捕获在不同线程中运行的方法的异常的正确方法是什么?

qt - QML listview 过度滚动

c++ - 多态性 C++