Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get focus (or tab) order

Tags:

qt

qt-designer

I have designed a user interface by using Qt Designer, and I have set the tab order using the "edit tab order" mode.

Now what I'd like to know (for an other reason, not so important) is how to get the tab order of a specific QWidget in the ui?

I mean if I have several widgets, and say the tab order has been set, is there a way to do something like :

int nb = widget1->getTabOrder();
like image 694
gpalex Avatar asked Nov 22 '13 21:11

gpalex


People also ask

What does tab order mean?

Tab Order is the order or sequence that the cursor moves from field to field. Initially, the tab order is determined by the order in which the fields are added to the form. In many cases, as fields are moved around the page, added from a template, or pasted from somewhere else, the tab sequence may become disorganized.

How is tab order determined?

Control tab order is determined by the order in which controls are drawn on the screen. The first control that you draw is assigned a tab order of 1 , the next is given tab order number 2 , and so on.

What should tab order?

The default keyboard navigation order must be logical and intuitive. The tab order should follow the visual flow of the page: left to right, top to bottom – header first, then main navigation, then page navigation (if present), and finally the footer.

What is the focus order?

Success Criterion 2.4. 3 Focus Order (Level A): If a Web page can be navigated sequentially and the navigation sequences affect meaning or operation, focusable components receive focus in an order that preserves meaning and operability.


1 Answers

There is no way to get the tab order as an integer. If you look into the C++ code that the uic tool creates from your ui file, it will call QWidget::setTabOrder() a few times, and that method just takes two QWidget pointers. Thus, Qt internally doesn't even store the tab order as an integer, but rather as a chained list of QWidget pointers.

You can query that chained list with QWidget::nextInFocusChain() and QWidget::previousInFocusChain(). This gives you the whole focus chain of the widget, containing all child widgets inside it, in the right order. Then you can get the real tab order list by checking their focusPolicy, enabled state and visible state, just like the inside implementation of the QWidget::focusNextPrevChild() function. If you really need an integer index here, you need to devise an algorithm yourself that calculates indices from that obtained tab order list.

like image 145
Thomas McGuire Avatar answered Oct 21 '22 21:10

Thomas McGuire