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 make QDialog receive all mouse and keyboard event inside it?

How to make QDialog receive all mouse and keyboard event inside it?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 986 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.
  • masterwangzxM Offline
    masterwangzxM Offline
    masterwangzx
    wrote on last edited by
    #1

    I want to make a QDialog close(call accept()) when I not do action in two minute. I already set QThread and QTimer to the QDialog.

    But I do not know how to make QTimer stop when some action occur(mouse event and keyboard event). The QDialog can not receive the child widgets' event. How can I receive all mouse and keyboard event inside the QDialog and not affect the child widgets to handle their events?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      Implement a EventFilter for the Dialog and when a mouse/keuboard occurs set a flag variable.
      When the timer fires, if the flag is set, reset it and restart the timer (you can use a single shoot timer for that instead)
      If the flag is not set close the dialog.

      [EDIT]
      Doesn't work !!
      I have no clue except to install a event filter for QApplication
      It is over complicated, see this

      Maybe you can deal with the move/leave/enter events at the window level ?

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

        Hi,

        You can make your dialog the filter of its child widgets and on mouse/keyboard events, restart the timer. As already suggested make the timer a single shot.

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

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Why not do it reverse?
          You pop the dialog + semi transparent overlay widget saying "Auto config"
          user can then click the overlay to change the setting or let it auto-accept.
          That way its clear it will auto accept and its much, much simpler to handle code wise.

          1 Reply Last reply
          0
          • M mpergand

            Implement a EventFilter for the Dialog and when a mouse/keuboard occurs set a flag variable.
            When the timer fires, if the flag is set, reset it and restart the timer (you can use a single shoot timer for that instead)
            If the flag is not set close the dialog.

            [EDIT]
            Doesn't work !!
            I have no clue except to install a event filter for QApplication
            It is over complicated, see this

            Maybe you can deal with the move/leave/enter events at the window level ?

            masterwangzxM Offline
            masterwangzxM Offline
            masterwangzx
            wrote on last edited by
            #5

            @mpergand Thanks for your help.

            I read the answer on stackoverflow.QCoreApplication::instance()->installEventFilter(this); this code is helpful to get event even inside the child widgets.

            I do not set such flag. I just stop and start the thread of the timer when the event filter get the key or mouse event.

            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