QGridLayout动态添加控件
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();
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html