Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved When do I know a qpushbutton is on focus?

    General and Desktop
    3
    5
    1420
    Loading More Posts
    • 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
      cimer84 last edited by

      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_ 1 Reply Last reply Reply Quote 0
      • the_
        the_ @cimer84 last edited by

        @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 Reply Quote 3
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • C
            cimer84 @SGaist last edited by

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

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 0
              • First post
                Last post