Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-05-2003, 07:26 PM   #1
LQ Newbie
Registered: Oct 2003
Posts: 8

Rep: Reputation: 0
Changing keyboard menu shortcuts in KDE/Gnome apps?

Is there any way to easily change/add keyboard menu shortcuts to Gnome or KDE apps? Either through the source code or else through a (Mac)Resedit-like utility? For example, one may want to change the quit menu shortcut from cntl-q to alt-q, or to add a keyboard shortcut to the "list bookmarks" menu item.

I did several searches of the boards, and the closest I got was here:

<CENSORED> LOL looks like newbies can't paste urls... anyway it is threadid 24807.

But that was for GTK apps, not normal KDE/Gnome apps.

Old 10-05-2003, 09:48 PM   #2
Registered: Jul 2003
Distribution: Debian Testing
Posts: 180

Rep: Reputation: 30
In almost any KDE application, there is a Settings->Shortcuts menu item.
Old 10-06-2003, 06:19 AM   #3
LQ Newbie
Registered: Oct 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Yeah, I saw that in a couple apps. I guess my question is more for gnome apps, how might I do it there? I would be willing to change source code as well, if there is no resedit-like utility. I imagine that this type of information is in a fairly standardized location in the source code for any gnome app...?
Old 10-07-2003, 09:06 PM   #4
LQ Newbie
Registered: Oct 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Well, I figured out the answer to my question, at least partially--for KDE apps that don't have a built-in shortcut-configuration mechanism. The solution involves changing source code, but it is a minor change. The shortcut won't show up in the menu itself (without some additional hackery which I deemed unnecesary since I already know what the shortcut is). But the shortcut will work, it will activate the menu item. For more explanation of this method, see

The code listed below goes into the constructor of the menu object (the object which extends some variant of KPopupMenu). The variables named kk... are my variables. The kk... variables that are newly allocated here (e.g. kkSignalMapper = new...) have to of course be deleted in the menu's destructor. They also have to be added to the member variable list for the menu class, which is usually contained in the header file. The header files that need to be included for the below code are:

#include <qsignalmapper.h>
#include <kaction.h>

So, here is the code:

1) kkSignalMapper = new QSignalMapper(this);
2) connect(kkSignalMapper, SIGNAL(mapped(int)), this, SLOT(activatedSlot(int)));
3) kkActionCollection = new KActionCollection(parent);
4) KAction* kkCurAction = new KAction(i18n("junk"), CTRL+Key_1, kkSignalMapper, SLOT(map()), kkActionCollection, "waste");
5) // Set shortcut to correspond to the index of the menu item you want (item 26 in this case)
6) kkSignalMapper->setMapping(kkCurAction, 26);

Now for a little explanation.

In all the lines, "this" corresponds to the menu object itself, since we are in the menu's constructor.

In line (2), "activatedSlot" is the name of the function in the menu class which defines what to do when a menu item is selected. This function comes with the code--it will be written already by the app author, and it may be called something different from "activatedSlot" of course. Typically this function will be basically a big switch statement that defines what to do if the menuitem index (integer passed in) equals 1 or 2 or whatever.

In line (3), "parent" corresponds to the parent variable passed into the menu constructor--this will usually be the main window, or the containing window. You need to use "parent" in line (3), not "this"--if you use "this", the shortcut will only work when the menu is actually open and displayed on the screen--which of course defeats the whole purpose of this exercise.

Line (4) defines what keystroke combination you want. The second parameter can be replaced by things line "SHIFT+CTRL+Key_P" or whatever you want. The first and last parameters are obviously nonsense and not used for this code. You can repeat this line multiple times, with different KAction* variables each time. Each line will correspond to a different keystroke. You should probably keep the first and last parameters unique for each call. For example, the next line might be:
KAction* kkCurAction2 = new KAction(i18n("junk2"), SHIFT+CTRL+Key_P, kkSignalMapper, SLOT(map()), kkActionCollection, "waste2");

Line 6 maps the action (containing the shortcut) created in line 4 with a menuitem index you want that shortcut to map to. You need one of these lines for every KAction you create above.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE Keyboard Shortcuts with different Keyboard Layout hellblade Linux - Software 5 04-18-2006 12:40 AM
Gnome Keyboard Shortcuts problem GaWin Ubuntu 2 07-29-2005 04:39 AM
Is it possible to assign keyboard shortcuts in GNOME apps? kornerr Linux - General 0 02-09-2005 09:39 AM
XFCE and kde/gnome apps (launcher menu question) JimDog Linux - Newbie 2 10-11-2003 07:43 AM
Custom Keyboard Shortcuts in Gnome mvanadel Linux - General 5 09-28-2003 12:20 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:11 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration