Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Strange behavior for mousePressEvent
Qt 6.11 is out! See what's new in the release blog

Strange behavior for mousePressEvent

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 3 Posters 1.9k Views 1 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.
  • L Offline
    L Offline
    lateDev
    wrote on last edited by
    #1

    Hello,
    I'm developing custom serial touchscreen-like driver around Linux evdev events. We have QT5 application on ARM mobile platform and I'm stuck with strange behavior inside QT events. The driver itself simulates an absolute mouse and, I'm confident, works fine on kernel level.
    QT environment is configured like this :

    export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
    export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2

    The driver sends (X Y) coordinates, button and button state in following format:
    (X,Y, btn_number, btn_state).
    So I'm sending (100,100, 1, 1) expecting mouse left button press in 100,100 location. And eventually (100,100, 1, 0) to release button. What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1) when in reality I'm sending (100,100, 1, 1) . Then all following clicks will have an offset of (100,100). It looks like the first coordinates are setting up some kind of relative offset. So following this logic, I need to send (200,200,1,1) to have a click in (100,100, 1, 1). To make it work properly I have to always send the first click to (0,0, 1, 1) then magically everything works until the system reboot. There is no accumulation so it's not like QT is not set to ABS. It will be always the exact same offset using the first click coordinates as value.
    So this is not on kernel driver level, I see the data on evtest /dev/input/event2 and the data is valid. It's just QT taking the first click coordinates as reference point!
    Any advise where I should look to fix this?

    Thanks all!

    JonBJ jeremy_kJ 2 Replies Last reply
    0
    • L lateDev

      Hello,
      I'm developing custom serial touchscreen-like driver around Linux evdev events. We have QT5 application on ARM mobile platform and I'm stuck with strange behavior inside QT events. The driver itself simulates an absolute mouse and, I'm confident, works fine on kernel level.
      QT environment is configured like this :

      export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
      export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2

      The driver sends (X Y) coordinates, button and button state in following format:
      (X,Y, btn_number, btn_state).
      So I'm sending (100,100, 1, 1) expecting mouse left button press in 100,100 location. And eventually (100,100, 1, 0) to release button. What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1) when in reality I'm sending (100,100, 1, 1) . Then all following clicks will have an offset of (100,100). It looks like the first coordinates are setting up some kind of relative offset. So following this logic, I need to send (200,200,1,1) to have a click in (100,100, 1, 1). To make it work properly I have to always send the first click to (0,0, 1, 1) then magically everything works until the system reboot. There is no accumulation so it's not like QT is not set to ABS. It will be always the exact same offset using the first click coordinates as value.
      So this is not on kernel driver level, I see the data on evtest /dev/input/event2 and the data is valid. It's just QT taking the first click coordinates as reference point!
      Any advise where I should look to fix this?

      Thanks all!

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @lateDev said in Strange behavior for mousePressEvent:

      What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1)

      Where are you calling what code for this mousePressEvent()? For example, QWidget::mousePressEvent(QMouseEvent *event) has event->position() (as opposed to globalPosition()) as relative to the widget. But maybe you know you have a situation/problem outside of this.

      L 1 Reply Last reply
      0
      • JonBJ JonB

        @lateDev said in Strange behavior for mousePressEvent:

        What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1)

        Where are you calling what code for this mousePressEvent()? For example, QWidget::mousePressEvent(QMouseEvent *event) has event->position() (as opposed to globalPosition()) as relative to the widget. But maybe you know you have a situation/problem outside of this.

        L Offline
        L Offline
        lateDev
        wrote on last edited by
        #3

        @JonB
        There are different widgets but they all look like this:
        void GridWidget::mousePressEvent(QMouseEvent *event)
        {
        lastPos = mapToGlobal(event->pos());
        pressPos = mapToGlobal(event->pos());
        printf("[GridWidget] mousePressEvent pos: %d, globalPos: %d, X: %d, Y: %d, globalX: %d, globalY: %d, button:%d\n",
        event->pos(), event->globalPos(), event->x(), event->y(), event->globalX(), event->globalY(), event->button());
        }
        This printf always returns 0 for coordinates during the first press. Then starts returning (data - offset from the first press) for consecutive presses.

        By chance, do you know where data goes between:

        input_report_abs(input_v_mouse, ABS_X, pos->xPos);
        input_report_abs(input_v_mouse, ABS_Y, pos->yPos);
        input_report_key(input_v_mouse, BTN_LEFT, button->status);
        input_sync(input_v_mouse);

        in driver and

        mousePressEvent() callback in QT?

        Perhaps something happens is in this middle layer but I don't know where to look.

        Thank you!

        1 Reply Last reply
        0
        • L lateDev

          Hello,
          I'm developing custom serial touchscreen-like driver around Linux evdev events. We have QT5 application on ARM mobile platform and I'm stuck with strange behavior inside QT events. The driver itself simulates an absolute mouse and, I'm confident, works fine on kernel level.
          QT environment is configured like this :

          export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
          export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2

          The driver sends (X Y) coordinates, button and button state in following format:
          (X,Y, btn_number, btn_state).
          So I'm sending (100,100, 1, 1) expecting mouse left button press in 100,100 location. And eventually (100,100, 1, 0) to release button. What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1) when in reality I'm sending (100,100, 1, 1) . Then all following clicks will have an offset of (100,100). It looks like the first coordinates are setting up some kind of relative offset. So following this logic, I need to send (200,200,1,1) to have a click in (100,100, 1, 1). To make it work properly I have to always send the first click to (0,0, 1, 1) then magically everything works until the system reboot. There is no accumulation so it's not like QT is not set to ABS. It will be always the exact same offset using the first click coordinates as value.
          So this is not on kernel driver level, I see the data on evtest /dev/input/event2 and the data is valid. It's just QT taking the first click coordinates as reference point!
          Any advise where I should look to fix this?

          Thanks all!

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by jeremy_k
          #4

          My first step is usually to turn on all debugging output.
          export QT_LOGGING_RULES=".=true"

          QT_DEBUG_PLUGINS=1 might help as well.

          @lateDev said in Strange behavior for mousePressEvent:

          export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
          export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2

          If QT_QPA_EVDEV_MOUSE_PARAMETERS is not empty, the specification portion of the plugin passed via QT_QPA_GENERIC_PLUGINS is discarded. Either don't use QT_QPA_EVDEV_MOUSE_PARAMETERS, or use that to pass the full configuration, including abs.

          https://codebrowser.dev/qt5/qtbase/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp.html#58

          QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent)
              : QObject(parent), m_x(0), m_y(0), m_xoffset(0), m_yoffset(0)
          {
              Q_UNUSED(key);
              QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS"));
              if (spec.isEmpty())
                  spec = specification;
              auto parsed = QEvdevUtil::parseSpecification(spec);
          

          Asking a question about code? http://eel.is/iso-c++/testcase/

          L 1 Reply Last reply
          0
          • jeremy_kJ jeremy_k

            My first step is usually to turn on all debugging output.
            export QT_LOGGING_RULES=".=true"

            QT_DEBUG_PLUGINS=1 might help as well.

            @lateDev said in Strange behavior for mousePressEvent:

            export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
            export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2

            If QT_QPA_EVDEV_MOUSE_PARAMETERS is not empty, the specification portion of the plugin passed via QT_QPA_GENERIC_PLUGINS is discarded. Either don't use QT_QPA_EVDEV_MOUSE_PARAMETERS, or use that to pass the full configuration, including abs.

            https://codebrowser.dev/qt5/qtbase/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp.html#58

            QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent)
                : QObject(parent), m_x(0), m_y(0), m_xoffset(0), m_yoffset(0)
            {
                Q_UNUSED(key);
                QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS"));
                if (spec.isEmpty())
                    spec = specification;
                auto parsed = QEvdevUtil::parseSpecification(spec);
            
            L Offline
            L Offline
            lateDev
            wrote on last edited by lateDev
            #5

            @jeremy_k
            Thank you for suggestions!
            Putting all config in QT_QPA_EVDEV_MOUSE_PARAMETERS doesn't work, if I remove
            QT_QPA_GENERIC_PLUGINS evdevmouse
            QT stops receiving events.
            So I'm stuck with :
            export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2:abs
            export QT_QPA_GENERIC_PLUGINS evdevmouse
            which seems to translate driver events to QT.
            I don't have qevdevmousemanager sources, only .h in my environment.
            And my .h is quite different from the one in your link.
            Yours is:

            class QEvdevMouseManager : public QObject
            {
            public:
                QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = nullptr);
                ~QEvdevMouseManager();
                void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons,
                                      Qt::MouseButton button, QEvent::Type type);
                void handleWheelEvent(QPoint delta);
                void addMouse(const QString &deviceNode = QString());
                void removeMouse(const QString &deviceNode);
            private:
                void clampPosition();
                void updateDeviceCount();
                QString m_spec;
                QtInputSupport::DeviceHandlerList<QEvdevMouseHandler> m_mice;
                int m_x;
                int m_y;
                int m_xoffset;
                int m_yoffset;
            };
            

            And this is mine:

            class QEvdevMouseManager : public QObject
            {
                Q_OBJECT
            public:
                QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = 0);
                ~QEvdevMouseManager();
            
                QDeviceDiscovery *deviceDiscovery() { return m_deviceDiscovery; }
            
            public slots:
                void handleMouseEvent(int x, int y, Qt::MouseButtons buttons);
                void handleWheelEvent(int delta, Qt::Orientation orientation);
            
            private slots:
                void addMouse(const QString &deviceNode = QString());
                void removeMouse(const QString &deviceNode);
            
            private:
                QString m_spec;
                QHash<QString,QEvdevMouseHandler*> m_mice;
                QDeviceDiscovery *m_deviceDiscovery;
                int m_x;
                int m_y;
                int m_xoffset;
                int m_yoffset;
            };
            

            My handleMouseEvent() doesn't have bool abs parameter which brings me to think that perhaps it's not made to work with absolute mouses. Is there any possibility to add this function to my environment? What would be the library to recompile?
            I don't have sources but these are all QT libraries I have in my environment:
            libfunnyutil.so
            libfunnyutil.so.1
            libfunnyutil.so.1.0
            libfunnyutil.so.1.0.0
            libQt5Concurrent.so
            libQt5Concurrent.so.5
            libQt5Concurrent.so.5.3
            libQt5Concurrent.so.5.3.2
            libQt5Core.so
            libQt5Core.so.5
            libQt5Core.so.5.3
            libQt5Core.so.5.3.2
            libQt5DBus.so
            libQt5DBus.so.5
            libQt5DBus.so.5.3
            libQt5DBus.so.5.3.2
            libQt5Gui.so
            libQt5Gui.so.5
            libQt5Gui.so.5.3
            libQt5Gui.so.5.3.2
            libQt5Multimedia.so
            libQt5Multimedia.so.5
            libQt5Multimedia.so.5.3
            libQt5Multimedia.so.5.3.2
            libQt5MultimediaWidgets.so
            libQt5MultimediaWidgets.so.5
            libQt5MultimediaWidgets.so.5.3
            libQt5MultimediaWidgets.so.5.3.2
            libQt5Network.so
            libQt5Network.so.5
            libQt5Network.so.5.3
            libQt5Network.so.5.3.2
            libQt5PrintSupport.so
            libQt5PrintSupport.so.5
            libQt5PrintSupport.so.5.3
            libQt5PrintSupport.so.5.3.2
            libQt5Sql.so
            libQt5Sql.so.5
            libQt5Sql.so.5.3
            libQt5Sql.so.5.3.2
            libQt5Widgets.so
            libQt5Widgets.so.5
            libQt5Widgets.so.5.3
            libQt5Widgets.so.5.3.2
            libQt5Xml.so
            libQt5Xml.so.5
            libQt5Xml.so.5.3
            libQt5Xml.so.5.3.2

            jeremy_kJ 1 Reply Last reply
            0
            • L lateDev

              @jeremy_k
              Thank you for suggestions!
              Putting all config in QT_QPA_EVDEV_MOUSE_PARAMETERS doesn't work, if I remove
              QT_QPA_GENERIC_PLUGINS evdevmouse
              QT stops receiving events.
              So I'm stuck with :
              export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2:abs
              export QT_QPA_GENERIC_PLUGINS evdevmouse
              which seems to translate driver events to QT.
              I don't have qevdevmousemanager sources, only .h in my environment.
              And my .h is quite different from the one in your link.
              Yours is:

              class QEvdevMouseManager : public QObject
              {
              public:
                  QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = nullptr);
                  ~QEvdevMouseManager();
                  void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons,
                                        Qt::MouseButton button, QEvent::Type type);
                  void handleWheelEvent(QPoint delta);
                  void addMouse(const QString &deviceNode = QString());
                  void removeMouse(const QString &deviceNode);
              private:
                  void clampPosition();
                  void updateDeviceCount();
                  QString m_spec;
                  QtInputSupport::DeviceHandlerList<QEvdevMouseHandler> m_mice;
                  int m_x;
                  int m_y;
                  int m_xoffset;
                  int m_yoffset;
              };
              

              And this is mine:

              class QEvdevMouseManager : public QObject
              {
                  Q_OBJECT
              public:
                  QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = 0);
                  ~QEvdevMouseManager();
              
                  QDeviceDiscovery *deviceDiscovery() { return m_deviceDiscovery; }
              
              public slots:
                  void handleMouseEvent(int x, int y, Qt::MouseButtons buttons);
                  void handleWheelEvent(int delta, Qt::Orientation orientation);
              
              private slots:
                  void addMouse(const QString &deviceNode = QString());
                  void removeMouse(const QString &deviceNode);
              
              private:
                  QString m_spec;
                  QHash<QString,QEvdevMouseHandler*> m_mice;
                  QDeviceDiscovery *m_deviceDiscovery;
                  int m_x;
                  int m_y;
                  int m_xoffset;
                  int m_yoffset;
              };
              

              My handleMouseEvent() doesn't have bool abs parameter which brings me to think that perhaps it's not made to work with absolute mouses. Is there any possibility to add this function to my environment? What would be the library to recompile?
              I don't have sources but these are all QT libraries I have in my environment:
              libfunnyutil.so
              libfunnyutil.so.1
              libfunnyutil.so.1.0
              libfunnyutil.so.1.0.0
              libQt5Concurrent.so
              libQt5Concurrent.so.5
              libQt5Concurrent.so.5.3
              libQt5Concurrent.so.5.3.2
              libQt5Core.so
              libQt5Core.so.5
              libQt5Core.so.5.3
              libQt5Core.so.5.3.2
              libQt5DBus.so
              libQt5DBus.so.5
              libQt5DBus.so.5.3
              libQt5DBus.so.5.3.2
              libQt5Gui.so
              libQt5Gui.so.5
              libQt5Gui.so.5.3
              libQt5Gui.so.5.3.2
              libQt5Multimedia.so
              libQt5Multimedia.so.5
              libQt5Multimedia.so.5.3
              libQt5Multimedia.so.5.3.2
              libQt5MultimediaWidgets.so
              libQt5MultimediaWidgets.so.5
              libQt5MultimediaWidgets.so.5.3
              libQt5MultimediaWidgets.so.5.3.2
              libQt5Network.so
              libQt5Network.so.5
              libQt5Network.so.5.3
              libQt5Network.so.5.3.2
              libQt5PrintSupport.so
              libQt5PrintSupport.so.5
              libQt5PrintSupport.so.5.3
              libQt5PrintSupport.so.5.3.2
              libQt5Sql.so
              libQt5Sql.so.5
              libQt5Sql.so.5.3
              libQt5Sql.so.5.3.2
              libQt5Widgets.so
              libQt5Widgets.so.5
              libQt5Widgets.so.5.3
              libQt5Widgets.so.5.3.2
              libQt5Xml.so
              libQt5Xml.so.5
              libQt5Xml.so.5.3
              libQt5Xml.so.5.3.2

              jeremy_kJ Offline
              jeremy_kJ Offline
              jeremy_k
              wrote on last edited by
              #6

              @lateDev said in Strange behavior for mousePressEvent:

              I don't have qevdevmousemanager sources, only .h in my environment.
              And my .h is quite different from the one in your link.

              The platform interface has a history of being more volatile. If the vendor is reasonably responsive, asking for a full copy might might save a lot of time.

              My handleMouseEvent() doesn't have bool abs parameter which brings me to think that perhaps it's not made to work with absolute mouses. Is there any possibility to add this function to my environment? What would be the library to recompile?
              I don't have sources but these are all QT libraries I have in my environment:

              The absolute coordinate change originates with commit 1d4a1be - https://codereview.qt-project.org/c/qt/qtbase/+/81593
              That was merged in March of 2014. It looks like the change made it into Qt 5.4.0.

              libQt5Core.so.5.3.2

              That concurs with my investigation. If you have any reasonable route to upgrade, it will save a lot of headaches.

              Asking a question about code? http://eel.is/iso-c++/testcase/

              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