[Konsole-devel] [PATCH] Shortcuts with hidden menu bar

Robin Stocker robin at nibor.org
Tue Jul 24 15:47:00 UTC 2007


Hi,

As Konsole is probably the application I use the most, I thought I might
help a little with the development of the interesting KDE 4 version.

The attached patch makes the action shortcuts work with a hidden menu
bar. It applies to trunk/KDE/kdebase/apps/konsole.

The problem was: In Qt4, invisible widgets don't get events anymore,
because that's usually how you want it to behave. Because the actions
are added to the menu and the menu is hidden, the shortcuts do not work.


There are several solutions:

- In the *ui.rc files, add each action not only to <MenuBar>, but also
to <MainWindow>. Not good.

- Add all actions of actionCollection to the main window after they are
all added. I grepped for takeAction, to see if any actions are removed,
but found nothing. This is the method I implemented in the patch.

- actionCollection provides the signal inserted(QAction *). Connect the
signal to a new slot in MainWindow which adds the action. One would also
have to provide a new method for the signal removed, so this would
amount to four slots in two classes.


The best solution would be to use KActionCollection.addAssociatedWidget,
but in line 238 of kdelibs/kdeui/actions/kactioncollection.cpp, before
the action is added to the specified widget, it does this:

        action->setShortcutContext(Qt::WidgetShortcut);

Because of this, the shortcut will only get triggered when the main
window widget is directly focussed, but that's never the case.

I don't know where actionCollection is used, but maybe this code could
be changed; maybe add a method setAssociatedWidgetShortcutContext or
something like it. Because then, this would be the cleanest solution.


Cheers,
  Robin Stocker
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: shortcuts-with-hidden-menubar.diff
URL: <http://mail.kde.org/pipermail/konsole-devel/attachments/20070724/06186aea/attachment.ksh>


More information about the konsole-devel mailing list