How to exclude a widget from tab-ordering list?
Asked Answered
C

1

16

enter image description here

(This picture is from Qt official site, and I take it as an example.)

I'd like to escape some unimportant widgets from being tab-focused.

(This strategy is useful if you have a widget that you want to quickly rotate between some commonly used QLineEdit to enter data and escape those rarely used settings.)

Take the picture as an example, is it possible to exclude Width and Height from tab-ordering list so I can use Tab to rotate only between Name, Color depth, OK and Cancel? I've searched the document and didn't find the option to remove widgets from tab-ordering list.

Clipped answered 30/5, 2014 at 11:8 Comment(2)
You can disable elements, if you don't want them to be focusable. Is it what you need?Heliotherapy
I still want to use them. Thuga's answer is what I want: I can set those unimportant widgets to be Qt::ClickFocus and they will be excluded from my tab-ordering list, meanwhile I can still use them by click on them.Clipped
G
28

Change the focus policy of your widgets that you don't want in the tab order list.

The policy is Qt::TabFocus if the widget accepts keyboard focus by tabbing.

You will have to set it to Qt::ClickFocus or Qt::NoFocus to remove it from the tab order list.

See what different focus policies do here.

Gretta answered 30/5, 2014 at 11:18 Comment(2)
It works pretty well, very appreciate! Btw, setting Qt::NoFocus on a QLineEdit seems equivalent to disable it.Clipped
@Clipped Yes, widget with Qt::NoFocus set as its focus policy will not accept keyboard focus at all.Gretta

© 2022 - 2024 — McMap. All rights reserved.