Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to monitor user activity on widget?
Forum Updated to NodeBB v4.3 + New Features

How to monitor user activity on widget?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 984 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.
  • T Offline
    T Offline
    Teem
    wrote on last edited by
    #1

    I have a user control widget with many input options for user.

    I want to set up a user activity timer and when it hits the end - hide this widget(later user can open it by clicking the screen).

    What I did for now is that I created new timer and placed timer->start() at each button press event, but this does not work everywhere.

    I tried to use *MousePressEvent * for widget, but this does not works for buttons.

    Is there anything that could restart my timer anytime user interacts with the widget (presses buttons or moves slider, switches between tabs)?

    Thanks
    Tim

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      if you just care about any user input you can do this simple trick:

      MyWidget::MyWidget(QWidget* parent) : QWidget(parent)
      {
          qApp->installEventFilter(this);
      }
      
      bool MyWidget::eventFilter(QObject* watched, QEvent* event)
      {
           if( watched->isWidgetType() )
           {
                  QWidget* w = static_cast<QWidget*>(watched);
                  switch( event->type() )
                  {
                          case QEvent::MouseButtonPress:
                          case QEvent::MouseButtonRelease:
                          case QEvent::KeyPress:
                          case QEvent::KeyRelease:
                          // remove the following if not needed
                          case QEvent::TouchBegin:
                          case QEvent::TouchUpdate:
                          case QEvent::TouchEnd:
                          {
                                 if( this->isAncestorOf(w) )
                                     // restart timer here
                          }
                          break;
                  }
           }
      
           return QWidget::eventFilter(watched,event);
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      T 1 Reply Last reply
      0
      • raven-worxR raven-worx

        if you just care about any user input you can do this simple trick:

        MyWidget::MyWidget(QWidget* parent) : QWidget(parent)
        {
            qApp->installEventFilter(this);
        }
        
        bool MyWidget::eventFilter(QObject* watched, QEvent* event)
        {
             if( watched->isWidgetType() )
             {
                    QWidget* w = static_cast<QWidget*>(watched);
                    switch( event->type() )
                    {
                            case QEvent::MouseButtonPress:
                            case QEvent::MouseButtonRelease:
                            case QEvent::KeyPress:
                            case QEvent::KeyRelease:
                            // remove the following if not needed
                            case QEvent::TouchBegin:
                            case QEvent::TouchUpdate:
                            case QEvent::TouchEnd:
                            {
                                   if( this->isAncestorOf(w) )
                                       // restart timer here
                            }
                            break;
                    }
             }
        
             return QWidget::eventFilter(watched,event);
        }
        
        T Offline
        T Offline
        Teem
        wrote on last edited by
        #3

        @raven-worx

        Thanks! Added default case to remove build warnings and it works fine!

        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