QML - 移动自定义无框窗口

时间:2016-03-17 20:03:41

标签: c++ qt qml

我找到了如何做窗口可拖动,但是它使用旧的QT,我不知道如何在当前的QT / QML中做到:/请帮帮我

http://stackoverflow.com/questions/18927534/qtquick2-dragging-frameless-window

它不起作用,因为它使用Viewer,我不能在我的应用程序中使用它。

我的main.cpp:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

2 个答案:

答案 0 :(得分:0)

我找到了怎么做,很容易:D

event.preventDefault()

答案 1 :(得分:0)

您可以很简单。像下面的代码

Rectangle {
    id: rect
    width: 100
    height: 100
    color: "red"
    MouseArea {
        anchors.fill: parent
        drag{ target: parent; axis: Drag.XandYAxis}

        onMouseXChanged: {
            if(drag.active){
                print(rect.x)
            }
        }

        onMouseYChanged: {
            if(drag.active)
            {
                print(rect.y)
            }
        }
    }
}

谢谢