1、动态生成
QGridLayout* lay = new QGridLayout(); int total = paras.size(); int colum = 4; for(int i=0; i<total; i++){ Zparam* pZparam = new Zparam(this); m_params.push_back(pZparam); lay->addWidget(pZparam, i/colum, i%colum); } this->setLayout(lay);
Zparam自定义QWidget子类;m_params用来存储动态生成的控件,便于回收
2、回收
delete this->layout(); for(int i=0; i<(int)m_params.size(); i++){ delete m_params[i]; } m_params.clear();