Qt里怎么从layout里移除控件
1个4x4的gridlayout 有16个窗体
现在变为3x3 想先把里面的窗体都移除 然后再加入9个
调用removeWidget方法似乎无效 求解应该如何从layout里移除widget?
right_above_layout->removeWidget(vec_VideoWidget[i]);
[解决办法]
直接把gridlayout delete掉试试
[解决办法]
我最近在公司做一个项目,刚好有这个需求,我贴出这部分代码,自己慢慢去研究吧。
void CentralWidget::setDrivePlateAddrAndElectronStorageCabinetCount(int drivePlateAddr, int electronStorageCabinetCount)
{
int prevCount = info->getElectronStorageCabinetCount();
for(int i = 0; i < prevCount; ++i)
{
delete labels[i];
labels[i] = NULL;
}
labels.clear();
for(int i = 0; i < electronStorageCabinetCount; ++i)
labels.append(new Label(this));
for(int i = 0; i < electronStorageCabinetCount; ++i)
{
int row = i / LINE_COUNT;
int column = i % LINE_COUNT;
gridLayout->addWidget(labels[i], row, column);
}
for(int i = 0; i < labels.count(); ++i)
{
connect(labels[i], SIGNAL(updateBoxDoorCheckState(int)), this, SLOT(updateBoxDoorCheckState(int)));
connect(labels[i], SIGNAL(updateGoodsCheckState(int)), this, SLOT(updateGoodsCheckState(int)));
}
info->initInfo(drivePlateAddr, electronStorageCabinetCount);
}