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. Capture all user inputs (screensaver)

Capture all user inputs (screensaver)

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 6.5k 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.
  • B Offline
    B Offline
    bundickt
    wrote on last edited by
    #1

    I have a timer that will cause a screensaver to start after a certain amount of time of no user activity. I need a way to restart the timer when the user initiates any kind of input: key press or mouse event. I wanted to know if there is a global signal I can connect to that will send me a signal whenever there is a user event. I also need that user event to be sent to the qml element that is in active focus. I am trying to avoid putting a restart timer call in all the button on the screen.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You can install an event filter ("QObject::installEventfilter() ":http://doc.qt.nokia.com/stable/qobject.html#installEventFilter)on your QApplication object. You can react on the events you are interested in an send them further to their actual recipient(s). I'm not a QML export, but I guess that you will have to add this in a small C++ class.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ngocketit
        wrote on last edited by
        #3

        I guess it can be something like this: you create a class, let's call it UserInputDetector that installs an event filter for the QApplication object. Inside the filter, you catch all events that make the timer restart and emit a signal when the events occur. Then, you put an instance of this class in a plugin and use it inside QML code (e.g, catching the signal to act appropriately):

        @UserInputDetector::UserInputDetector(QObject *parent) :
        {
        qApp->installEventFilter(this);
        }

        bool UserInputDetector::eventFilter(QObject *obj, QEvent *event)
        {
        Q_UNUSED(obj);
        switch (event->type()) {
        case QEvent::KeyRelease:
        case QEvent::KeyPress:
        case QEvent::MouseButtonPress:
        case QEvent::MouseMove:
        case QEvent::MouseButtonRelease:
        emit userEventOccurred();
        break;
        default:
        break;
        }
        return false;
        }@

        And the plugin:
        @void UserInputDetectorPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
        {
        Q_UNUSED(uri)
        engine->rootContext()->setContextProperty("userInputDetector", new UserInputDetector(engine));
        }

        Q_EXPORT_PLUGIN2(userInputDetectorPlugin, UserInputDetectorPlugin);@

        And inside QML:
        @Connections {
        target: userInputDetector
        onUserEventOccurred: timer.restart();
        }@

        1 Reply Last reply
        1
        • B Offline
          B Offline
          bundickt
          wrote on last edited by
          #4

          Thanks,
          That is exactly what I needed.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ecloud
            wrote on last edited by
            #5

            How did that turn out? I was also thinking of trying to write a screen saver, but did you make an open-source project of this already?

            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