Moving the window does not work correctlyMoving the window on holding Qml MouseAreaSubclassed QWidget does not move correctlyQML states does not workQML MouseArea onEntered hoverEnabled does not workQML window resize/move flickerQML - Moving custom frameless windowQML: monitoring mouse moving event in the “whole” windowMoving qml Item out of left side of windowWhy is this code to find the window size in QML not working?`visible: false` statement doesn't work on Windows but it works on Linux
Why does string strummed with finger sound different from the one strummed with pick?
Is there any official Lore on Keraptis the Wizard, apart from what is in White Plume Mountain?
Who is frowning in the sentence "Daisy looked at Tom frowning"?
Better than Rembrandt
How can sister protect herself from impulse purchases with a credit card?
Is it a good idea to teach algorithm courses using pseudocode instead of a real programming language?
Why does the U.S military use mercenaries?
Can 2 light bulbs of 120V in series be used on 230V AC?
Generating random, non-repeating points on the plane
Latin words remembered from high school 50 years ago
Isn't Kirchhoff's junction law a violation of conservation of charge?
Is it possible to view all the attribute data in QGIS
Is there a developer API for Agile Accelerator?
Are there any crystals that are theoretically possible, but haven't yet been made?
How can I stop my kitten from growing?
Addressing an email
Is a reptile with diamond scales possible?
pwaS eht tirsf dna tasl setterl fo hace dorw
Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario
How do you play the middle D and F in this passage?
Is being an extrovert a necessary condition to be a manager?
Most efficient way to switch on SObjectType?
How do I find the ID of a custom field, contribution, option value, etc.?
Why does Taylor’s series “work”?
Moving the window does not work correctly
Moving the window on holding Qml MouseAreaSubclassed QWidget does not move correctlyQML states does not workQML MouseArea onEntered hoverEnabled does not workQML window resize/move flickerQML - Moving custom frameless windowQML: monitoring mouse moving event in the “whole” windowMoving qml Item out of left side of windowWhy is this code to find the window size in QML not working?`visible: false` statement doesn't work on Windows but it works on Linux
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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 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();
qt qml
add a comment |
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 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();
qt qml
You should read the documentation more carefully. The parameter of MouseArea.MouseArea is mouse. There is nomouseXormouseYand 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.
– folibis
Mar 24 at 7:19
I fixed my code a bit, but still, the effect remained. Maybe you know a working solution? I can't figure it out.
– Michael Shcherbakov
Mar 24 at 8:46
There is no item with idmainWindow, 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.
– folibis
Mar 24 at 8:53
I have two files in my project: main.cpp and main.qml. I added them. And still doesn't work for me.
– Michael Shcherbakov
Mar 24 at 9:09
window.x += (mouse.x - lastMouseX)this is always incremental and will grow indefinitely.
– bardao
Mar 26 at 23:09
add a comment |
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 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();
qt qml
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 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();
qt qml
qt qml
edited Mar 24 at 9:09
Michael Shcherbakov
asked Mar 23 at 18:25
Michael ShcherbakovMichael Shcherbakov
1084
1084
You should read the documentation more carefully. The parameter of MouseArea.MouseArea is mouse. There is nomouseXormouseYand 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.
– folibis
Mar 24 at 7:19
I fixed my code a bit, but still, the effect remained. Maybe you know a working solution? I can't figure it out.
– Michael Shcherbakov
Mar 24 at 8:46
There is no item with idmainWindow, 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.
– folibis
Mar 24 at 8:53
I have two files in my project: main.cpp and main.qml. I added them. And still doesn't work for me.
– Michael Shcherbakov
Mar 24 at 9:09
window.x += (mouse.x - lastMouseX)this is always incremental and will grow indefinitely.
– bardao
Mar 26 at 23:09
add a comment |
You should read the documentation more carefully. The parameter of MouseArea.MouseArea is mouse. There is nomouseXormouseYand 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.
– folibis
Mar 24 at 7:19
I fixed my code a bit, but still, the effect remained. Maybe you know a working solution? I can't figure it out.
– Michael Shcherbakov
Mar 24 at 8:46
There is no item with idmainWindow, 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.
– folibis
Mar 24 at 8:53
I have two files in my project: main.cpp and main.qml. I added them. And still doesn't work for me.
– Michael Shcherbakov
Mar 24 at 9:09
window.x += (mouse.x - lastMouseX)this is always incremental and will grow indefinitely.
– bardao
Mar 26 at 23:09
You should read the documentation more carefully. The parameter of MouseArea.MouseArea is mouse. There is no
mouseX or mouseY and so you store some random values. Also note that mouse.x is real and so you lose precision while storing it in int. Another recommendation is to use debugger, it allows to solve such problems in moment.– folibis
Mar 24 at 7:19
You should read the documentation more carefully. The parameter of MouseArea.MouseArea is mouse. There is no
mouseX or mouseY and so you store some random values. Also note that mouse.x is real and so you lose precision while storing it in int. Another recommendation is to use debugger, it allows to solve such problems in moment.– folibis
Mar 24 at 7:19
I fixed my code a bit, but still, the effect remained. Maybe you know a working solution? I can't figure it out.
– Michael Shcherbakov
Mar 24 at 8:46
I fixed my code a bit, but still, the effect remained. Maybe you know a working solution? I can't figure it out.
– Michael Shcherbakov
Mar 24 at 8:46
There is no item with id
mainWindow, the ApplicationWindow.visible is 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.– folibis
Mar 24 at 8:53
There is no item with id
mainWindow, the ApplicationWindow.visible is 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.– folibis
Mar 24 at 8:53
I have two files in my project: main.cpp and main.qml. I added them. And still doesn't work for me.
– Michael Shcherbakov
Mar 24 at 9:09
I have two files in my project: main.cpp and main.qml. I added them. And still doesn't work for me.
– Michael Shcherbakov
Mar 24 at 9:09
window.x += (mouse.x - lastMouseX) this is always incremental and will grow indefinitely.– bardao
Mar 26 at 23:09
window.x += (mouse.x - lastMouseX) this is always incremental and will grow indefinitely.– bardao
Mar 26 at 23:09
add a comment |
1 Answer
1
active
oldest
votes
Even if you manage to solve this using QML you will see that the window will move with a LOT of jitter. It's mainly because of how bindings work (asynchronously). A better approach is asking C++ for QCursor::pos()
Here's a brief way on how to do that:
In your main.qml create a MouseArea:
MouseArea
property var clickPos
anchors.fill: parent
onPressed:
clickPos = x: mouse.x, y: mouse.y
onPositionChanged:
window.x = cpp_helper_class.cursorPos().x - clickPos.x
window.y = cpp_helper_class.cursorPos().y - clickPos.y
In your c++ cpp_helper_class you should have the following method:
Q_INVOKABLE QPointF cursorPos() return QCursor::pos();
The Q_INVOKALBE makes sure your C++ code is accessible from QML.
Also your main.cpp should contain the following:
context->setContextProperty("cpp_helper_class", &helper_class_instance);
It works amazingly. Thanks.
– Michael Shcherbakov
Mar 27 at 13:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317033%2fmoving-the-window-does-not-work-correctly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Even if you manage to solve this using QML you will see that the window will move with a LOT of jitter. It's mainly because of how bindings work (asynchronously). A better approach is asking C++ for QCursor::pos()
Here's a brief way on how to do that:
In your main.qml create a MouseArea:
MouseArea
property var clickPos
anchors.fill: parent
onPressed:
clickPos = x: mouse.x, y: mouse.y
onPositionChanged:
window.x = cpp_helper_class.cursorPos().x - clickPos.x
window.y = cpp_helper_class.cursorPos().y - clickPos.y
In your c++ cpp_helper_class you should have the following method:
Q_INVOKABLE QPointF cursorPos() return QCursor::pos();
The Q_INVOKALBE makes sure your C++ code is accessible from QML.
Also your main.cpp should contain the following:
context->setContextProperty("cpp_helper_class", &helper_class_instance);
It works amazingly. Thanks.
– Michael Shcherbakov
Mar 27 at 13:47
add a comment |
Even if you manage to solve this using QML you will see that the window will move with a LOT of jitter. It's mainly because of how bindings work (asynchronously). A better approach is asking C++ for QCursor::pos()
Here's a brief way on how to do that:
In your main.qml create a MouseArea:
MouseArea
property var clickPos
anchors.fill: parent
onPressed:
clickPos = x: mouse.x, y: mouse.y
onPositionChanged:
window.x = cpp_helper_class.cursorPos().x - clickPos.x
window.y = cpp_helper_class.cursorPos().y - clickPos.y
In your c++ cpp_helper_class you should have the following method:
Q_INVOKABLE QPointF cursorPos() return QCursor::pos();
The Q_INVOKALBE makes sure your C++ code is accessible from QML.
Also your main.cpp should contain the following:
context->setContextProperty("cpp_helper_class", &helper_class_instance);
It works amazingly. Thanks.
– Michael Shcherbakov
Mar 27 at 13:47
add a comment |
Even if you manage to solve this using QML you will see that the window will move with a LOT of jitter. It's mainly because of how bindings work (asynchronously). A better approach is asking C++ for QCursor::pos()
Here's a brief way on how to do that:
In your main.qml create a MouseArea:
MouseArea
property var clickPos
anchors.fill: parent
onPressed:
clickPos = x: mouse.x, y: mouse.y
onPositionChanged:
window.x = cpp_helper_class.cursorPos().x - clickPos.x
window.y = cpp_helper_class.cursorPos().y - clickPos.y
In your c++ cpp_helper_class you should have the following method:
Q_INVOKABLE QPointF cursorPos() return QCursor::pos();
The Q_INVOKALBE makes sure your C++ code is accessible from QML.
Also your main.cpp should contain the following:
context->setContextProperty("cpp_helper_class", &helper_class_instance);
Even if you manage to solve this using QML you will see that the window will move with a LOT of jitter. It's mainly because of how bindings work (asynchronously). A better approach is asking C++ for QCursor::pos()
Here's a brief way on how to do that:
In your main.qml create a MouseArea:
MouseArea
property var clickPos
anchors.fill: parent
onPressed:
clickPos = x: mouse.x, y: mouse.y
onPositionChanged:
window.x = cpp_helper_class.cursorPos().x - clickPos.x
window.y = cpp_helper_class.cursorPos().y - clickPos.y
In your c++ cpp_helper_class you should have the following method:
Q_INVOKABLE QPointF cursorPos() return QCursor::pos();
The Q_INVOKALBE makes sure your C++ code is accessible from QML.
Also your main.cpp should contain the following:
context->setContextProperty("cpp_helper_class", &helper_class_instance);
answered Mar 26 at 23:04
bardaobardao
360317
360317
It works amazingly. Thanks.
– Michael Shcherbakov
Mar 27 at 13:47
add a comment |
It works amazingly. Thanks.
– Michael Shcherbakov
Mar 27 at 13:47
It works amazingly. Thanks.
– Michael Shcherbakov
Mar 27 at 13:47
It works amazingly. Thanks.
– Michael Shcherbakov
Mar 27 at 13:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317033%2fmoving-the-window-does-not-work-correctly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You should read the documentation more carefully. The parameter of MouseArea.MouseArea is mouse. There is no
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.– folibis
Mar 24 at 7:19
I fixed my code a bit, but still, the effect remained. Maybe you know a working solution? I can't figure it out.
– Michael Shcherbakov
Mar 24 at 8:46
There is no item with id
mainWindow, 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.– folibis
Mar 24 at 8:53
I have two files in my project: main.cpp and main.qml. I added them. And still doesn't work for me.
– Michael Shcherbakov
Mar 24 at 9:09
window.x += (mouse.x - lastMouseX)this is always incremental and will grow indefinitely.– bardao
Mar 26 at 23:09