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
Earned some good credits
Earned some good credits
Posts: 147
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 » Tue Aug 27, 2019 9:58 pm

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
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 696
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 » Tue Aug 27, 2019 11:24 pm

Use mybutton->SetCanFocus(false) See https://docs.wxwidgets.org/trunk/classw ... 66f1b7f3d8

tomay3000
Earned some good credits
Earned some good credits
Posts: 147
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 » Wed Aug 28, 2019 12:40 am

Unfortunately, it didn't worked under Windows 7 :(

User avatar
doublemax
Moderator
Moderator
Posts: 13989
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 » Wed Aug 28, 2019 11:17 am

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