0

I can enumerate widgets inside layout but I need to enumerate widgets inside layouts inside layout...

I'm trying:

  while (QHBoxLayout* currentLayout = m_Layout->findChild<QHBoxLayout*>()) {
    while (QCheckBox* currentCheckbox = currentLayout->findChild<QCheckBox*>()) {
      if (currentCheckbox->isChecked()) {

      }
    }
  }

But this code just stucks... I guess it's maybe because I can't find QHBoxLayout, is there other possible ways I can enumerate layout inside layouts?

Thank you

cnd
  • 32,616
  • 62
  • 183
  • 313
  • `QLayout::itemAt()` might help. – vahancho Jun 23 '15 at 11:02
  • One question. Is `while (QCheckBox* currentCheckbox = currentLayout->findChild())` returning a list of widgets? If there are several direct ancestors, it is undefined which one will be returned. In that case, `findChildren()` should be used. – Tarod Jun 23 '15 at 11:07

1 Answers1

1
for (int i = 0; i < layout->count(); ++i) {
    QLayoutItem *item = layout->itemAt(i);
    if (item->widget()) {
        processWidget(item->widget());
    } else if (item->layout()) {
        processLayout(item->layout());
    }
}
Amartel
  • 4,248
  • 2
  • 15
  • 21