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();
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With