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. When do I know a qpushbutton is on focus?
QtWS25 Last Chance

When do I know a qpushbutton is on focus?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.7k 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.
  • C Offline
    C Offline
    cimer84
    wrote on last edited by
    #1

    I have a QDialogButtonBox and i want to know how I can get when the Qpushbutton is on focus, because a i need it to disccard and event.

    the_T 1 Reply Last reply
    0
    • C cimer84

      I have a QDialogButtonBox and i want to know how I can get when the Qpushbutton is on focus, because a i need it to disccard and event.

      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      @cimer84

      You can use eventFilter for this.

      //in the header file of YourClass
      
        bool eventFilter(QObject *, QEvent *);
      
      //somewhere in the cpp file of YourClass
      
      bool YourClass::eventFilter(QObject* watched, QEvent* event) {
      
        if( event->type() == QEvent::FocusIn) {
          //do something when the watched object(s) gets focus
        }
      
        if( event->type() == QEvent::FocusOut) {
          //do something when the watched object(s) loses focus
        }
        return QWidget::eventFilter(watched, event);
      }
      

      and after initializing the QDialogButtonBox and its buttons

      button->installEventFilter(this);
      

      to install the filter.

      hope that helps

      -- No support in PM --

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

        Hi,

        If you don't want the possible interaction with a QPushButton, why not just disable it ?

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

        C 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          If you don't want the possible interaction with a QPushButton, why not just disable it ?

          C Offline
          C Offline
          cimer84
          wrote on last edited by
          #4

          @SGaist No the interaction is with other functionality not with the QPushButton

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Can you give an example ?

            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
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved