Reputation: 216
I have a QT5 application in which I have to simulate a tab keypress on an external event i.e. I need to cycle through the taborder list and setFocus on the next element.
I cannot find any method to get the tab-order list programmatically. What would be the best way to do this?
Upvotes: 0
Views: 950
Reputation: 4869
How about a combination of QWidget::
nextInFocusChain() / previousInFocusChain() and setFocus() method or setFocus() slot? (There are some other ways to set focus as well, all cross-linked in the Qt docs.)
nextInFocusChain()
and previousInFocusChain()
provide public API access to the underlying private members which seem to control the tabbing order. You can see them being used in QWidget::setTabOrder() for example.
Current focus widget could be found with either QWidget::focusWidget() of the parent widget, or QApplication::focusWidget(). Note that QWidget::focusWidget()
will also return the first widget in the focus order if none currently have focus. This starting point could be used to build a list of widgets in tab order.
Upvotes: 2