Qt布局相关的问题
1.消除布局间的空隙
QVBoxLayout *h_layout=new QVBoxLayout();
h_layout->setMargin(0);
h_layout->setSpacing(0);
h_layout->setContentsMargins(0,0,0,0);
2.清除原有布局
while(h_main->count())
{
QWidget *pWidget=h_main->itemAt(0)->widget();
if (pWidget)
{
pWidget->setParent (nullptr);
h_main->removeWidget(pWidget);
delete pWidget;
}
else
{
QLayout *pLayout=h_main->itemAt(0)->layout();
if (pLayout)
{
while(pLayout->count())
{
QWidget *pTempWidget=pLayout->itemAt(0)->widget();
if (pTempWidget)
{
pTempWidget->setParent (nullptr);
pLayout->removeWidget(pTempWidget);
delete pTempWidget;
}
else
{
pLayout->removeItem(pLayout->itemAt(0));
}
}
}
h_main->removeItem(h_main->itemAt(0));
}
}
参考
qt删除已有布局