Search code examples
c++qtqtwidgets

How can I enumerate layouts inside layout?


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


Solution

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