【问题标题】:QML - Moving custom frameless windowQML - 移动自定义无框窗口
【发布时间】:2016-07-04 09:29:45
【问题描述】:

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

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

它不工作,因为它使用查看器,我无法在我的应用程序中使用它。

我的 main.cpp:

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

    return app.exec();
}

【问题讨论】:

    标签: c++ qt qml


    【解决方案1】:

    我找到了方法,很简单:D

    MouseArea {
                anchors.fill: parent
                property real lastMouseX: 0
                property real lastMouseY: 0
                onPressed: {
                    lastMouseX = mouseX
                    lastMouseY = mouseY
                }
                onMouseXChanged: window.x += (mouseX - lastMouseX)
                onMouseYChanged: window.y += (mouseY - lastMouseY)
            }
    

    【讨论】:

      【解决方案2】:

      你可以很简单。如下代码

      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)
                  }
              }
          }
      }
      

      谢谢

      【讨论】:

        猜你喜欢
        • 2017-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-10
        相关资源
        最近更新 更多