Shortcut keys for QButtons

Login or register to post comments
7 replies [Last post]
alex94040's picture
Offline
Joined: 11/06/2008

Folks,

I recently added a "keyboard shortcut key" concept for QButtons in my app. The idea is that I can define a button, just like I always would:

$objButton = new QButton($this);
$objButton->Text = "Save";
$objButton->AddAction(new QClickEvent(), new QAjaxAction('button_clicked'));

And then I can say "add a keyboard shortcut Ctrl+S - whenever the user presses it, behave as if the user pressed the button". I encapsulated it like this:

$objButton->AddShortcut('ctrl', 'S');

What this does is establishes a shortcut key, and also changes the Text value of the objButton to make the shortcut more discoverable (it finds the first S in the text of the button, and changes that S to be underlined and have a slightly bigger font - just like all good ol' Windows applications have it).

My code is based upon this library: http://www.openjs.com/scripts/events/keyboard_shortcuts/

There's a jquery port: http://code.google.com/p/js-hotkeys/.

Question: is anyone interested in me making this into a plugin? Or, if there's a lot of interest, I can happily add this to QButtonBase.

Offline
Joined: 04/01/2008

I love this idea! I'd like to see it in the base myself ...

Offline
Joined: 03/31/2008

It's too bad there's so much extra JS there. If you can get it to only include that .js file when the feature is actually in use, I think this is globally applicable and worth putting in core. :)

alex94040's picture
Offline
Joined: 11/06/2008

Here's what I think I can do: as soon as the user calls AddKeyboardShortcut() on the button, that method will call AddJavascriptFile(). How does that sound, folks?

Offline
Joined: 03/31/2008

Sounds great. :) That function already checks for dupes, so I think we're golden.

Offline
Joined: 05/20/2010

Was this ever implemented? I'm currently working on a project where it would be very helpful.

Offline
Joined: 08/07/2009

hi,

I would also be very interested in seeing this as a plugin or directly in QButtonBase.

thanks,
Tom

alex94040's picture
Offline
Joined: 11/06/2008

Moved my code here: http://trac.qcu.be/projects/qcubed/ticket/727

Does someone have some time to take it to the next level and get it ready for the inclusion into the core?