获取焦点(或标签)顺序 [英] Get focus (or tab) order

查看:84
本文介绍了获取焦点(或标签)顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Qt Designer 设计了一个用户界面,并使用编辑 Tab 键顺序"模式设置了 Tab 键顺序.

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

现在我想知道(出于其他原因,不是那么重要)是如何在 ui 中获取特定 QWidget 的 Tab 键顺序?

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?

我的意思是,如果我有几个小部件,并说已经设置了 Tab 键顺序,是否有办法执行以下操作:

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 键顺序设为整数.如果您查看 uic 工具从您的 ui 文件创建的 C++ 代码,它会调用 QWidget::setTabOrder() 几次,而该方法只需要两个 QWidget> 指针.因此,Qt 在内部甚至不会将 Tab 键顺序存储为整数,而是将其存储为 QWidget 指针的链表.

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.

您可以使用 QWidget::nextInFocusChain()QWidget::previousInFocusChain() 查询该链表.这为您提供了小部件的整个焦点链,其中包含按正确顺序包含在其中的所有子小部件.然后你就可以通过检查它们的focusPolicy、启用状态和可见状态来获得真正的Tab顺序列表,就像QWidget::focusNextPrevChild()函数的内部实现一样.如果你真的需要一个整数索引,你需要自己设计一个算法,根据获得的 Tab 键顺序列表计算索引.

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.

这篇关于获取焦点(或标签)顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆