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. event filter not called before menu shortcut dispatch
Forum Updated to NodeBB v4.3 + New Features

event filter not called before menu shortcut dispatch

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 593 Views 3 Watching
  • 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #1

    in my QApplication i have a key-down filter:

    class QKJams : public QApplication {
    	typedef QApplication _inherited;
    	public:
    
    	QKJams(int argc, char *argv[]) :
    		_inherited(argc, argv)
    	{
    		installEventFilter(this);
    	}
    
    	bool	event(QEvent *eventP)
    	{
    		QEvent::Type	eventType(eventP->type());
    		
    		switch (eventType) {
    			
    			case QEvent::KeyPress: {
    • <-- breakpoint  handledB = _inherited::event(eventP);
    			} break;
    		}
    		return handledB;
    	}
    
    	bool	eventFilter(QObject *objP, QEvent *eventP)
    	{
    		bool			handledB = false;
    
    		switch (eventP->type()) {
    			case QEvent::KeyPress: {
    • <-- breakpoint  handledB = _inherited::eventFilter(objP, eventP);
    			} break;
    		}
    		return handledB;
    	}
    };
    

    yet keyboard shortcuts are sent to the menu handler BEFORE the app either filters OR handles the event. the breakpoints above are not hit when i press a key that happens to be an unmodified shortcut key in the menu bar.

    the doc says the App should get a crack at the event BEFORE any other processing, which i took to mean before looking in the menu bar for a matching key shortcut.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by davecotter
      #2

      update: only if i remove the key shortcut from the menu, then it works, but backwards from what i thought it should do: first the Window filter get called, then the App filter. i thought the App filter would get called FIRST, then window, then menubar?

      Axel SpoerlA 1 Reply Last reply
      0
      • D davecotter

        update: only if i remove the key shortcut from the menu, then it works, but backwards from what i thought it should do: first the Window filter get called, then the App filter. i thought the App filter would get called FIRST, then window, then menubar?

        Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by
        #3

        @davecotter said in event filter not called before menu shortcut dispatch:

        first the Window filter get called

        Hi David,
        Unless I have missed something here: I don’t find that “Window filter” in the code.
        Cheers
        Axel

        Software Engineer
        The Qt Company, Oslo

        1 Reply Last reply
        0
        • D Offline
          D Offline
          davecotter
          wrote on last edited by
          #4

          well i didn't post the full project. but it is there, trust me.

          my question is: is it expected that it goes: menus, windows, app ? and not the other way around?

          Pl45m4P JonBJ 2 Replies Last reply
          0
          • D davecotter

            well i didn't post the full project. but it is there, trust me.

            my question is: is it expected that it goes: menus, windows, app ? and not the other way around?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @davecotter

            Hi, you say it stops working when you add the menu shortcut?!
            what's the context of your menu shortcut?

            • https://doc.qt.io/qt-6/qt.html#ShortcutContext-enum

            and not the other way around?

            Propagation in the QObject tree is bottom up, starting with the "inner-most" child at event "position".

            If you want to handle the same application-wide shortcut with your menu, try to set it to Qt::ApplicationShortcut otherwise the Qt::WindowShortcut from your menu in your Window will accept and eat the key/shortcut event and it will never reach your application handler...
            There is an article in the Qt Documentation about shortcut contexts and ambiguity... can't find it right now.

            Btw:

            @davecotter said in event filter not called before menu shortcut dispatch:

              installEventFilter(this);
            

            This line, which is short for this->installEventFilter(this); doesn't make too much sense :)
            A QObject doesn't need an eventFilter to watch its own events, it will receive and handle them anyway using QObject::event() and all the more specific event handlers (like QWidget::mouseMoveEvent or key-press-Events... etc.).


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            3
            • D davecotter

              well i didn't post the full project. but it is there, trust me.

              my question is: is it expected that it goes: menus, windows, app ? and not the other way around?

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @davecotter
              As @Pl45m4 has written, events go to the "most specific, innermost" widget first. If that handles/accepts the event that's it; if it does not/rejects then the next outer widget gets to have a go, and so on up the hierarchy tree. If you define something like an ApplicationShortcut that by-passes the usual handling and goes straight to that handler.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                davecotter
                wrote on last edited by
                #7

                so are menu bar keyboard shortcuts considered the "most specific" ?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  davecotter
                  wrote on last edited by
                  #8

                  I guess that's my question 👆🏻

                  Pl45m4P 1 Reply Last reply
                  0
                  • D davecotter

                    I guess that's my question 👆🏻

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #9

                    @davecotter

                    and that 👉 https://forum.qt.io/post/808209 is my answer.
                    Have you tried it? Does it work?


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    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