The problem is that the coordinates of the window are not set correctly. Therefore, the window is moved incorrectly and errors appear:
QWindowsWindow::setGeometry: Unable to set geometry 400x400+62998+32284 on QQuickApplicationWindow_QML_0/''...
I don't know how to fix this. Here's the code:
main.qml
import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
visible: true
width: 400
height: 400
title: qsTr('Frameless')
flags: Qt.Window | Qt.FramelessWindowHint
Rectangle {
width: parent.width
height: 40
color: "gold"
anchors.top: parent.top
Text {
anchors.verticalCenter: parent.verticalCenter
leftPadding: 8
text: window.title
color: "white"
}
MouseArea {
anchors.fill: parent
property real lastMouseX: 0
property real lastMouseY: 0
onPressed: {
lastMouseX = mouse.x
lastMouseY = mouse.y
}
onMouseXChanged: window.x += (mouse.x - lastMouseX)
onMouseYChanged: window.y += (mouse.y- lastMouseY)
}
}
}
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
mouseXormouseYand so you store some random values. Also note thatmouse.xis real and so you lose precision while storing it inint. Another recommendation is to use debugger, it allows to solve such problems in moment. - folibismainWindow, theApplicationWindow.visibleis false by default, you have to set it to true explicitly. It looks like you provide a code different from one you test and there are some other factors that affect the window position. With fixed code that works for me well. - folibiswindow.x += (mouse.x - lastMouseX)this is always incremental and will grow indefinitely. - bardao