我在Qt中創建了一個允許用戶在QGraphicsView中拖動各種「模塊」的應用程序。只要選擇這些模塊中的一個,它發出的信號,然後由一個「ConfigurationWidget」,這是一個側面面板,其應顯示所有選擇的模塊的相關參數的拾起:在Qt中清除佈局
class ConfigurationWidget : public QWidget
{
Q_OBJECT
public:
ConfigurationWidget(QWidget *parent) : QWidget(parent) {}
public slots:
void moduleSelected(Module* m)
{
if(layout())
{
while (itsLayout->count()>0)
{
delete itsLayout->takeAt(0);
}
}
delete layout();
itsLayout = new QFormLayout(this);
itsLayout->addRow(QString(tr("Type:")), new QLabel(m->name()));
itsLayout->addRow(QString(tr("Instance:")), new QLabel(m->instanceID()));
// ... Display a whole bunch of other fields that depends on the module
}
};
問題當選擇模塊時ConfigurationWidget從未真正被清除。新的領域只是在舊的領域。我嘗試過hide()和show(),invalidate(),update()等各種組合,無濟於事。
什麼是正確的方式來使一個小部件,可以改變它的領域像這樣在飛行中?
你應該使用QStackedWidget – armonge 2011-01-31 23:16:32