QML Mouse drag laggy
Unsolved
QML and Qt Quick
-
Hello,
I've done a simple example of a rectangle which i drag, but somehow the rectangle always laggs behind the mouse/ the position of the rect isn't updated fast enough. What am i doing wrong? How to fix this? (when dragging fast it looks okish but when dragging slow it really feels sluggish and unprecise)
Windows 10, 64bit, Qt6.5, NVIDIA Graphicscard
EDIT: Setting QQuickwindow to Software rendering fixes it, but that really CAN'T be the solution! Because obviously when working with graphics drag and drop using the GPU is important!
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickWindow> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQuickWindow::setGraphicsApi(QSGRendererInterface::Software); QQmlApplicationEngine engine; QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("QMLCourseLesson2Graphics", "Main"); return app.exec(); }
Here is my code:
import QtQuick Window { id: root width: 640 height: 480 visible: true title: qsTr("Hello World") Rectangle{ id: myRect width: 100 height: 100 color: "blue" function update(){ console.log(x + " x "+ y) myRectLabel.text = Math.round(x) + " x "+ Math.round(y) } //anchors.centerIn: parent x: 100 y: 100 onXChanged: update() onYChanged: update() Component.onCompleted: update() Text { id: myRectLabel text: qsTr("text") anchors.centerIn: parent } MouseArea{ anchors.fill: parent drag.target: parent } /* // Add the DragHandler for dragging the rectangle DragHandler { id: dragHandler target: myRect // Specifies which item is dragged onActiveChanged: { if (dragHandler.active) { console.log("Drag started") } else { console.log("Drag ended") } } }*/ } }