【发布时间】:2015-06-23 10:59:43
【问题描述】:
我可以枚举布局内的小部件,但我需要枚举布局内的小部件...
我正在尝试:
while (QHBoxLayout* currentLayout = m_Layout->findChild<QHBoxLayout*>()) {
while (QCheckBox* currentCheckbox = currentLayout->findChild<QCheckBox*>()) {
if (currentCheckbox->isChecked()) {
}
}
}
但是这段代码卡住了......我想这可能是因为我找不到 QHBoxLayout,还有其他可能的方法可以枚举布局中的布局吗?
谢谢
【问题讨论】:
-
QLayout::itemAt()可能会有所帮助。 -
一个问题。
while (QCheckBox* currentCheckbox = currentLayout->findChild<QCheckBox*>())是否返回小部件列表?如果有多个直系祖先,则未定义将返回哪一个。在这种情况下,应该使用findChildren()。