I know, that I can delete QWidget from QLayout so:
QLayoutItem*item = wlay->takeAt(0);
wlay->removeItem(item);
delete item;
delete w;
However, without deleting QWidget(delete w), the widget will be on the screen. However, I cant delete the widget, so the widget will be on the screen. How to delete the widget from screen after removing it from layout? For example, I have so code:
class QTest: public QWidget{
Q_OBJECT
QVBoxLayout* wlay;
QPushButton* b;
public:
QTest(){
wlay = new QVBoxLayout();
b = new QPushButton("click");
for(int i = 0; i < 20; i++)
wlay->addWidget(new QLabel( "TEST" + QString::number(i)));
wlay->addWidget(b);
this->setLayout(wlay);
connect(b, &QPushButton::clicked, this, &QTest::doit);
}
public slots:
void doit();
};
void QTest::doit(){
//Removing all QLabel from Layout
for(int i =0; i < 20; i++){
QLayoutItem*item = wlay->takeAt(0);
wlay->removeItem(item);
delete item;
}
}
After removing QLabels from layout, labels are showed on screen. How to remove them from main Widget(without deleting them)?

