QtQuick2拖动无框窗口 [英] QtQuick2 dragging frameless window

查看:50
本文介绍了QtQuick2拖动无框窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在 QtQuick2 中拖动无框窗口的方法.我在论坛链接上关注了这个帖子,但它给了我一个错误.>

代码的主要区别在于我的代码使用 QtQuick2ApplicationViewer 而不是 QmlApplicationViewer 并且看起来 QtQuick2ApplicationViewer 没有.pos"财产.

这是我的 main.cpp

#include #include "qtquick2applicationviewer.h"#include int main(int argc, char *argv[]){QGuiApplication app(argc, argv);QtQuick2ApplicationViewer 查看器;viewer.rootContext()->setContextProperty("QmlApplicationViewer", (QObject *)&viewer);viewer.setFlags(Qt::FramelessWindowHint);viewer.setMainQmlFile(QStringLiteral("qml/ubusell/main.qml"));查看器.showExpanded();返回 app.exec();}

这是我的 main.qml 的一部分

MouseArea {id:鼠标区域anchors.fill:父级;属性变量 clickPos: "1,1"按下:{clickPos = Qt.point(mouse.x,mouse.y)}onPositionChanged:{var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)打印(QmlApplicationViewer.pos)QmlApplicationViewer.pos = (20,20)QmlApplicationViewer.pos = Qt.point(QmlApplicationViewer.pos.x+delta.x,QmlApplicationViewer.pos.y+delta.y)}}

当我尝试拖动窗口时出现此错误:

<块引用>

类型错误:无法读取未定义的属性x"

有什么想法吗?QtQuick2 甚至有可能吗?感谢帮助!

解决方案

在我的项目中,我这样做:

 属性变体 clickPos: "1,1"按下:{clickPos = Qt.point(mouse.x,mouse.y)}onPositionChanged:{var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)rootWindow.x += delta.x;rootWindow.y += delta.y;}

MouseArea中.

I’m looking for a way of dragging frameless window in QtQuick2. I followed this thread on the forum Link but it gives me an error.

Main difference in the code is that my code uses QtQuick2ApplicationViewer instead of QmlApplicationViewer and it looks like QtQuick2ApplicationViewer do not have ".pos" property.

This is my main.cpp

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QQmlContext>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.rootContext()->setContextProperty("QmlApplicationViewer", (QObject *)&viewer);
    viewer.setFlags(Qt::FramelessWindowHint);
    viewer.setMainQmlFile(QStringLiteral("qml/ubusell/main.qml"));
    viewer.showExpanded();

    return app.exec();
}

This is part of my main.qml

MouseArea {
    id: mouseRegion
    anchors.fill: parent;
    property variant clickPos: "1,1"

        onPressed: {
            clickPos  = Qt.point(mouse.x,mouse.y)
        }

        onPositionChanged: {
            var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
            print(QmlApplicationViewer.pos)
            QmlApplicationViewer.pos = (20,20)
            QmlApplicationViewer.pos = Qt.point(QmlApplicationViewer.pos.x+delta.x,
                              QmlApplicationViewer.pos.y+delta.y)
        }
}

When I try to drag window I get this error:

TypeError: Cannot read property 'x' of undefined

Any ideas ? Is it even possible with QtQuick2 ? Thanks for help!

解决方案

In my project I do:

property variant clickPos: "1,1"

onPressed: {
    clickPos  = Qt.point(mouse.x,mouse.y)
}

onPositionChanged: {
    var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
    rootWindow.x += delta.x;
    rootWindow.y += delta.y;
}

In MouseArea.

这篇关于QtQuick2拖动无框窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆