Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Mouse drag laggy
Forum Update on Monday, May 27th 2025

QML Mouse drag laggy

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmldraghandlermousearea
6 Posts 3 Posters 463 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StudentScripter
    wrote on 30 Oct 2024, 12:35 last edited by StudentScripter
    #1

    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

    Laggy drag with qml.gif

    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")
                    }
                }
            }*/
        }
    
    }
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      StudentScripter
      wrote on 15 Jan 2025, 14:09 last edited by
      #2

      BUMP has anyone a clue how to make the drag follow the mouse perfectly without massive delay?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrecKo
        Qt Champions 2018
        wrote on 15 Jan 2025, 15:49 last edited by
        #3

        Having a high refresh rate monitor 😬

        S 2 Replies Last reply 15 Jan 2025, 21:32
        1
        • G GrecKo
          15 Jan 2025, 15:49

          Having a high refresh rate monitor 😬

          S Offline
          S Offline
          StudentScripter
          wrote on 15 Jan 2025, 21:32 last edited by StudentScripter
          #4

          @GrecKo hm thats really a bummer. I have many apps where i drag stuff that where not written with qt but there it's possible without lagging behind. Seems to be poorly implemented in qml than. Anyway thanks for the answer.

          1 Reply Last reply
          0
          • G GrecKo
            15 Jan 2025, 15:49

            Having a high refresh rate monitor 😬

            S Offline
            S Offline
            StudentScripter
            wrote on 28 Jan 2025, 11:32 last edited by
            #5

            @GrecKo ... actually its the default VSYNC Setting of QML as i figured that increases the latency by ALOT! So for anyone searching just disable VSYNC an manage it yourself.

            Still a shame that i had to search multiple days to find a good solution. Should be better documented. Actually i do have 120hz...

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zinc
              wrote on 23 Apr 2025, 07:49 last edited by
              #6

              I v solve this problem:
              insert this 2 line code in main.cpp before create QGuiApplication object:

              qputenv("QSG_RENDER_LOOP", "basic" );
              QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
              
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved