Qt从布局中获得孩子 [英] Qt get children from layout

查看:102
本文介绍了Qt从布局中获得孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试隐藏布局中的所有小部件。但是看起来 findChildren 不能为布局使用

I try to hide all widgets in layout. But looks like findChildren doesn't work for layout.

这是我的示例代码:

QLayout * layout = widget -> findChild<QLayout *> (layoutName);
QList<QWidget *> list = layout -> findChildren<QWidget *> ();

cout << list.size() << endl;

size 为0,但在此布局内我有几个小部件。
但是如果我尝试从父窗口小部件获取窗口小部件,同样的代码也可以正常工作。

size is 0, but inside this layout I have a few widgets. But the same code works fine if I try to get widgets from parent widget.

如何从适当的布局中获取它们?

How I can get them from appropriate layout?

推荐答案

布局不会将其自身注入到父子树中,因此这些小部件将保留其父小部件的(直接)子级。

The layout does not "inject" itself in the parent-child tree, so the widgets stay (direct) children of their parent widget.

您可以使用 QLayout :: count() QLayout :: itemAt()

这篇关于Qt从布局中获得孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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