QT adds addWidget and clear removeWidget controls in the layout

1. Add controls to the layout:

ui->verticalLayout->addWidget(chartView);

2. Clear the control in the layout:

// 删除布局中所有的控件
while(ui->verticalLayout->count())
{
    
    
     QWidget *p=this->ui->verticalLayout->itemAt(0)->widget();
     p->setParent (NULL);
     this->ui->verticalLayout->removeWidget(p);
     delete p; // 清除内存
}

Guess you like

Origin blog.csdn.net/sazass/article/details/112906039