用Cofei的方法可以删除控件,不用hide()函数了。
但程序还是越运行所占的内存越大,找了很久不知是什么原因。
这个小程序的功能主要是根据不同的选项用PushButton在Layout中显示不同内衣的等码表。每显示一次前先将前一次显示的PushButton全部删掉。程序的主要代码如下:
void SizeLayout::showSizeLayout()
{
setViewType();
removeAllSizes();
setSizeFont();
int rowSpeed=rowSpeedSpin->value();
int columnSpeed=columnSpeedSpin->value();
QPalette pal=palette();
pal.setColor(QPalette::ButtonText,Qt::blue);
for(int row=0; row<cupRange.count(); row++)
{
for(int column=0; column<bandRange.count(); column++)
{
QPushButton *sizeButton = new QPushButton(tr("%1%2")
.arg(bandRange.value(column)).arg(cupRange.value(row)),this);
sizeButton->setPalette(pal);
//sizeButton->setStyleSheet ("background-color: rgb(180,180,180);color: rgb(15,15,15);");
sizeLayout->addWidget(sizeButton,row,column+row);
sleep(columnSpeed);
}
sleep(rowSpeed);
}
}
void SizeLayout::removeAllSizes()
{
QLayoutItem *sizeBtn;
while((sizeBtn=sizeLayout->takeAt(0)) !=0)
{
sizeBtn->widget()->setParent(0);
delete sizeBtn;
}
}