How to get wxButton with keyboard shortcut

437 views
Skip to first unread message

Andreas Falkenhahn

unread,
Jul 22, 2015, 11:21:27 AM7/22/15
to wx-u...@googlegroups.com
Could anybody point me to documentation/examples on how I can create
a wxButton with a keyboard shortcut that is underlined? e.g. in a
button named "T&est" I want ALT+e (or something similar) to be the
button's keyboard shortcut.

I have seen that this is possible with wxPython here:
http://stackoverflow.com/questions/23049406/wxpython-button-shortcut-accelerator-how-to-spam

But the documentation of wxButton doesn't mention anything about
keyboard shortcuts and when I set the button's label to something
like "T&est", the "e" is not rendered with an underscore on Windows 7.

Are keyboard shortcuts for buttons supported on all major platforms
(MSW, Cocoa, GTK) or is this a feature that is specific to wxPython?

--
Best regards,
Andreas Falkenhahn mailto:and...@falkenhahn.com

Vadim Zeitlin

unread,
Jul 22, 2015, 11:57:49 AM7/22/15
to wx-u...@googlegroups.com
On Wed, 22 Jul 2015 17:22:36 +0200 Andreas Falkenhahn wrote:

AF> Could anybody point me to documentation/examples on how I can create
AF> a wxButton with a keyboard shortcut that is underlined?

http://docs.wxwidgets.org/trunk/classwx_control.html#a2c2ae20554e7db5e765f163022ce09c0

AF> e.g. in a button named "T&est" I want ALT+e (or something similar) to
AF> be the button's keyboard shortcut.

If you use the label above it should already work.

AF> But the documentation of wxButton doesn't mention anything about
AF> keyboard shortcuts and when I set the button's label to something
AF> like "T&est", the "e" is not rendered with an underscore on Windows 7.

Have you tried pressing the "Alt" key?

AF> Are keyboard shortcuts for buttons supported on all major platforms
AF> (MSW, Cocoa, GTK)

Yes.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Andreas Falkenhahn

unread,
Jul 22, 2015, 1:11:25 PM7/22/15
to Vadim Zeitlin
On 22.07.2015 at 17:57 Vadim Zeitlin wrote:

> On Wed, 22 Jul 2015 17:22:36 +0200 Andreas Falkenhahn wrote:

AF>> Could anybody point me to documentation/examples on how I can create
AF>> a wxButton with a keyboard shortcut that is underlined?

> http://docs.wxwidgets.org/trunk/classwx_control.html#a2c2ae20554e7db5e765f163022ce09c0

AF>> e.g. in a button named "T&est" I want ALT+e (or something similar) to
AF>> be the button's keyboard shortcut.

> If you use the label above it should already work.

Oh right, it is really working. Don't know why I didn't see that.

Andreas Falkenhahn

unread,
Jul 22, 2015, 1:48:34 PM7/22/15
to Vadim Zeitlin
By the way, is this functionality documented somewhere? I don't see any information
about this in the documentation of wxButton. But I'd like to have some more information
on this keyboard shortcut functionality, from the top of my head, e.g.

- can wxWidgets use another token or is this hard-coded to the ampersand?
- how to escape an ampersand char in a wxButton's label? && seems to work but
I'd be more relaxed if this was documented somewhere
- which other widgets support those keyboard shortcuts? or is it only supported by
wxButton?

Thanks!

On 22.07.2015 at 17:57 Vadim Zeitlin wrote:

Catalin

unread,
Jul 22, 2015, 4:25:12 PM7/22/15
to wx-u...@googlegroups.com
On Wednesday, 22 July 2015, 20:48, Andreas Falkenhahn wrote:



By the way, is this functionality documented somewhere?

See wxControl::SetLabel(const wxString& label)

- can wxWidgets use another token or is this hard-coded to the ampersand?

It cannot use another token. Only ampersand works and it's the only one documented.

- how to escape an ampersand char in a wxButton's label? && seems to work but
  I'd be more relaxed if this was documented somewhere

&& is correct; same docs from above.

- which other widgets support those keyboard shortcuts? or is it only supported by
  wxButton?

Pretty much everything derived from wxControl supports this.

Regards,
C

Reply all
Reply to author
Forward
0 new messages