There is a layout that contains another sub-layout. At some point I need to delete this sub-Layout, and add a new one.

QVBoxLayout* mainLayout = new QVBoxLayout; //layout QHBoxLayout* subLayout = new QHBoxLayout; //под-layout for(int i = 0; i < 3; i++) subLayout->addWidget(new QPushButton(this)); //содержимое под-layout'a mainLayout->addLayout(subLayout); setLayout(mainLayout); 

After that, you need to remove the subLayout and its contents, and add a new one with other content.

How? QLayout provides only removeWidget , and absolutely no removeLayout, but just delete subLayout; no sensible effect.

  • Qt still alive? I remember as a child I wrote on it, when Nokia was still such a company, it produced phones. - Serge Esmanovich

2 answers 2

Use removeItem , this is exactly what you need.

    You should always assign a parent to the widget and layouts:

     QVBoxLayout* mainLayout = new QVBoxLayout(this); //layout QHBoxLayout* subLayout = new QHBoxLayout(this); //под-layout 

    In this case, delete should work.