How to prevent a wxButton from gaining the focus by pressing the TAB from the keyboard? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

How to prevent a wxButton from gaining the focus by pressing the TAB from the keyboard?

Post by tomay3000 »

Hello,
As asked in the title, how to do so, or simply remove this wxButton from the tab navigation order at all, and allow the focus to be set only by a mouse click.

TIA.
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: How to prevent a wxButton from gaining the focus by pressing the TAB from the keyboard?

Post by Manolo »

Use mybutton->SetCanFocus(false) See https://docs.wxwidgets.org/trunk/classw ... 66f1b7f3d8
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: How to prevent a wxButton from gaining the focus by pressing the TAB from the keyboard?

Post by tomay3000 »

Unfortunately, it didn't worked under Windows 7 :(
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to prevent a wxButton from gaining the focus by pressing the TAB from the keyboard?

Post by doublemax »

The cleanest version would be to subclass wxButton, override wxWindow::AcceptsFocusFromKeyboard() and return false there.
https://docs.wxwidgets.org/trunk/classw ... c6aa8301b8
Use the source, Luke!
Post Reply