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. QApplication, listen to all mice clicks...
QtWS25 Last Chance

QApplication, listen to all mice clicks...

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlqapplicationmouse control
2 Posts 1 Posters 866 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.
  • KroMignonK Offline
    KroMignonK Offline
    KroMignon
    wrote on last edited by
    #1

    Hi all,

    I have developed an Qt/QML application for embedded devices and all works fine.
    Some of those devices are used a resistive touch panel which has to be re-calibrated relative often, depending on hardware quality and temperature/humidity.

    To not annoying users with touch panel calibration on each application start, I would like to start calibration tool when user hits 10 times the screen in less than 5 seconds.
    Is there a way to capture all click events on application level (QApplication, perhaps QGuiApplication??) to be able to count mice clicks and measure elapsed time?

    Thanks for any suggestion

    Regards

    Fabrice

    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

    1 Reply Last reply
    0
    • KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      I reply to my self, perhaps there is someone else which have the same kind of issue ;-)

      In fact, it is quite easy, the solution is to use install an event filter on application level:

      class MouseEventFilter : public QObject
      {
          Q_OBJECT
      public:
          explicit MouseEventFilter(QObject *parent = 0);
      
      signals:
          void recalibrateTouch();
          
      public slots:
      
          // QObject interface
      public:
          bool eventFilter(QObject *object, QEvent *event)
          {
              if(event->type() == QEvent::MouseButtonPress)
              {
                  if(m_delay.hasExpired(5000))
                  {
                      m_clickCounter=0;
                      m_delay.start();
                  }
                  ++m_clickCounter;
                  if(m_clickCounter == 10)
                      emit recalibrateTouch();
              }
              return QObject::eventFilter(object,event);
          }
          
      private:
          int m_clickCounter;
          QElapsedTimer m_delay;
      };
      

      Then simply install the event filter on application level like this:

      app->installEventFilter(new MouseEventFilter(qApp));
      

      That's it :)
      Regards

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      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