Get focus (or tab) order

我们两清 提交于 2020-02-02 02:54:07

问题


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();

回答1:


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.



来源:https://stackoverflow.com/questions/20154635/get-focus-or-tab-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!