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. QMouseEvent bug?
Forum Updated to NodeBB v4.3 + New Features

QMouseEvent bug?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 310 Views 2 Watching
  • 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.
  • zzzpZ Offline
    zzzpZ Offline
    zzzp
    wrote last edited by
    #1

    There is a third-party library, libvnc, running in my Qt program to implement some VNC functionality. Recently, I encountered an issue.

    The Qt program acts as a VNC server. When I trigger a mouse event from a browser client to my Qt program, I simulate a corresponding mouse event based on the received coordinates. This process works correctly with most QML controls, but problems occur with certain controls, such as SwipeView, during drag operations. After investigation, I confirmed that the coordinates are accurate. The issue lies in the MousePress event—the press position of the QEventPoint generated internally never updates and always remains at the last point where my physical mouse was pressed.

    c7ca10b1-007c-4f08-b78f-9f6ddcc4d83e-image.png

    1f8b7739-5dbb-4ce6-ae63-4ab8be7ccd0e-image.png

    This causes some controls to be difficult to operate remotely during drag-and-drop or swipe gestures, due to the incorrect initial press position.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      You should give more details about your setup such as Qt version and OS you are running.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      zzzpZ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should give more details about your setup such as Qt version and OS you are running.

        zzzpZ Offline
        zzzpZ Offline
        zzzp
        wrote last edited by
        #3

        @SGaist This issue occurs in my Ubuntu 22.04 system when running the program with both eglfs and xcb. The Qt version is 6.5.3.

        1 Reply Last reply
        0
        • Axel SpoerlA Online
          Axel SpoerlA Online
          Axel Spoerl
          Moderators
          wrote last edited by
          #4

          @zzzp
          Please don't post images of text. Post code using the </> code tags.
          If your images (which I can barely view on my PC) refer to Qt code, then please add the file and line number.
          Also the setup is a bit unclear to me. You are saying that "Qt program" acts as a VNC server. Which program is that? Have you written it? You say that you trigger a mouse event from a browser. Are you using a browser as a VNC client? Which one?

          Software Engineer
          The Qt Company, Oslo

          zzzpZ 2 Replies Last reply
          0
          • Axel SpoerlA Axel Spoerl

            @zzzp
            Please don't post images of text. Post code using the </> code tags.
            If your images (which I can barely view on my PC) refer to Qt code, then please add the file and line number.
            Also the setup is a bit unclear to me. You are saying that "Qt program" acts as a VNC server. Which program is that? Have you written it? You say that you trigger a mouse event from a browser. Are you using a browser as a VNC client? Which one?

            zzzpZ Offline
            zzzpZ Offline
            zzzp
            wrote last edited by
            #5

            @Axel-Spoerl
            The VNC client is implemented using noVNC on the web, with Google Chrome as the browser. The VNC server is implemented within my own Qt program using the libvnc library.
            When the VNC server in the Qt program receives a mouse event, I construct a QMouseEvent and send it to my Qt application window. The detailed code is as follows:

            void VncServer::onMouseEvent(int buttonMask, int x, int y)
            {
                if (d->view) {
                    static int lastButtonMask = 0;
                    static QPointF lastLocalPos(-1, -1);
                    QPointF localPos(x, y);
                    //
                    // Qt::MouseButton mouseBtn = Qt::NoButton;     
                    Qt::MouseButtons mouseBtns = Qt::NoButton;      
                    Qt::KeyboardModifier keyboardModifier = Qt::NoModifier;
            
                    // buttonMask = 0 NoButton;= 1 LeftButton;= 2 MidButton;= 4 RightButton;
                    if(buttonMask & 1){
                        mouseBtns |= Qt::LeftButton;
                    }
                    if(buttonMask & 2){
                        mouseBtns |= Qt::MiddleButton;
                    }
                    if(buttonMask & 4){
                        mouseBtns |= Qt::RightButton;
                    }
                    if ((buttonMask & 1) && !(lastButtonMask & 1)) {
                        QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, Qt::LeftButton, mouseBtns, keyboardModifier);
                        QCoreApplication::postEvent(d->view, pressEvent);
                    }
                    if (!(buttonMask & 1) && (lastButtonMask & 1)) {
                        QMouseEvent *releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease, localPos, localPos, Qt::LeftButton, mouseBtns, keyboardModifier);
                        QCoreApplication::postEvent(d->view, releaseEvent);
                    }
                    if (buttonMask == lastButtonMask && localPos != lastLocalPos) {
                        QMouseEvent *moveEvent = new QMouseEvent(QEvent::MouseMove, localPos, localPos, Qt::NoButton, mouseBtns, keyboardModifier);
                        QCoreApplication::postEvent(d->view, moveEvent);
                    }
                    if(buttonMask & 8){
                        // Wheel up
                        Qt::ScrollPhase phase = Qt::NoScrollPhase;
                        QWheelEvent *upWheelEvent = new QWheelEvent(localPos, localPos, QPoint(0,120), QPoint(0,120), mouseBtns, keyboardModifier, phase, false);
                        QCoreApplication::postEvent(d->view, upWheelEvent);
                    }
                    if(buttonMask & 16){
                        // Wheel down
                        Qt::ScrollPhase phase = Qt::NoScrollPhase;
                        QWheelEvent *downWheelEvent = new QWheelEvent(localPos, localPos, QPoint(0,-120), QPoint(0,-120), mouseBtns, keyboardModifier, phase, false);
                        QCoreApplication::postEvent(d->view, downWheelEvent);
                    }
                    lastLocalPos = localPos;
                    lastButtonMask = buttonMask;
                }
            }
            

            Tip:My software runs in full-screen mode on the embedded device, so global-pos conversion does not need to be considered.

            qDebug()<<Q_FUNC_INF0 <<" pressEvent points="<< pressEvent->points();
            // console print this: QList(QEventPoint(id=0 ts=30877154 pos=1711,142 scn=1711,142 gbl=1831,219 Updated vel=-2910.61,1658.99 press=1879,50 last=1737,130  -26,12))
            

            No matter what mouse events I send from the VNC client, the press value (1879,50) never changes. It only updates when I physically click on the software using a local mouse within the Qt program.

            1 Reply Last reply
            0
            • Axel SpoerlA Axel Spoerl

              @zzzp
              Please don't post images of text. Post code using the </> code tags.
              If your images (which I can barely view on my PC) refer to Qt code, then please add the file and line number.
              Also the setup is a bit unclear to me. You are saying that "Qt program" acts as a VNC server. Which program is that? Have you written it? You say that you trigger a mouse event from a browser. Are you using a browser as a VNC client? Which one?

              zzzpZ Offline
              zzzpZ Offline
              zzzp
              wrote last edited by zzzp
              #6

              @Axel-Spoerl
              Alternatively, perhaps we should look beyond VNC? The real issue appears to be how to manage QEventPoint when there's no physical mouse and QMouseEvents are programmatically constructed within the application. Many drag-and-drop interactions in QML's native Qt controls seem to rely on it. If the press property cannot be modified, it will create significant usability issues.

              1 Reply Last reply
              0
              • Axel SpoerlA Online
                Axel SpoerlA Online
                Axel Spoerl
                Moderators
                wrote last edited by
                #7

                There is no bug with QMouseEvent, unless you provide a minimal reproducer showing that there is one :-)
                The VNC based issue looks more than a desktop or client/server compatibility issue to me.

                Software Engineer
                The Qt Company, Oslo

                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