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. Catch Qt::BackButton mouse events no matter which Widget is under the mouse cursor

Catch Qt::BackButton mouse events no matter which Widget is under the mouse cursor

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

    It seems that my
    @
    void MainWindow::mousePressEvent(QMouseEvent* event)
    @
    is only called when the mouse is not over controls that might also check for mousebuttons like an edit field. However, I want to globally catch the forward and backward mouse buttons to allow history navigation. Overriding mousePressEvent in QMainWindow does not seem to be the right way to do that then?

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

      you can install an eventfilter on your qApp instance.
      @
      qApp->installEventFilter(...);
      @

      Or you could subclass QApplication and reimplement notify() and listen for the event with the Qt::BackButton. You could also define a signal then.
      @
      virtual bool notify( QObject * receiver, QEvent * event )
      {
      if( event->type() == QEvent::MouseButtonPress )
      {
      QMouseEvent* me = static_cast<QMouseEvent*>(event);
      switch( me->button() )
      {
      case Qt::BackButton:
      emit navigateBackTriggered();
      break;
      case Qt::ForwardButton:
      emit navigateForwardTriggered();
      break;
      }
      return QApplication::notify(receiver, event);
      }
      @

      I would prefer to use the notify() method since it's ensured you really get all events (also the ones delivered to disabled widgets).

      --- 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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        philk
        wrote on last edited by
        #3

        Thanks, using the event filter works great!

        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