Disable menu activation on single Alt click



  • I am looking for any way to disable Menu Activation in Qt Application when single Alt is pressed. It is ok to have specific menu activated when I press for example Alt+F (to open &File menu). But the feature of moving focus to menu bar looks extremely inconvenient to me. When editing something in QTextEdit I often use Alt+Tab to switch to another window, or Alt+1, ..., Alt+9 to switch between applications tabs (I took this idea from gedit and I am very used to it, so integrated it into my application). Sometimes when I mistakenly press Alt extra time when switching the focus goes to menu and focus is loosed from QTextEdit. Even worse when I continue typing w/o noticing that focus gone to the menu bar sometimes arbitrary menu items can be activated (depending on the text I enter). So I am looking either for a way to disable this annoying feature in my application's code or disable it globally for all Qt applications in the system. It seems GTK menu bars are not activated this way, want disable single Alt activation for Qt applications as well. Any ideas?



  • Hi! I can think of two ways:

    1 If you are editing a text field, you could connect your textbox selectionChanged() signal with a custom MainWindow slot like blockMenu() so when the textbox is clicked your whole menu gets blocked and there won't be any accidental focus switching.

    2 Reimplement the keyPressEvent(QKeyEvent *) from your MainWindow class in order to preprocess any key that you press. Inside your keyPressEvent method, you could just ignore any "Alt" if it comes single, but if it comes with "Alt+1", for example, then you call a function that will do anything you want.

    If you're not familiar with keypressing methods, don't worry, you won't find it hard to learn.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.