I am still not sure on how to solve this issue.
Hopefully the following code will help to locate the missing calls in order to resize the main window. Here is how I add the new widgets at runtime:
lbltest
= new QLabel(ui
->tabw
);
lbltest
->setObjectName
(QString::fromUtf8("lbltest"));
lbltest->setAlignment(Qt::AlignCenter);
lbltest->setText("This is a test");
ui->gl1->addWidget(lbltest,4,0,1,1);
lbltest2
= new QLabel(ui
->tabw
);
lbltest2
->setObjectName
(QString::fromUtf8("lbltest2"));
lbltest2->setAlignment(Qt::AlignCenter);
lbltest2->setText("test");
ui->gl1->addWidget(lbltest2,5,0,1,1);
lbltest = new QLabel(ui->tabw);
lbltest->setObjectName(QString::fromUtf8("lbltest"));
lbltest->setAlignment(Qt::AlignCenter);
lbltest->setText("This is a test");
ui->gl1->addWidget(lbltest,4,0,1,1);
lbltest2 = new QLabel(ui->tabw);
lbltest2->setObjectName(QString::fromUtf8("lbltest2"));
lbltest2->setAlignment(Qt::AlignCenter);
lbltest2->setText("test");
ui->gl1->addWidget(lbltest2,5,0,1,1);
To copy to clipboard, switch view to plain text mode
This will work as expected and the mainwindow grows to accomodate the extra widgets.
Now I try to remove the labels with the following code:
if (lbltest != NULL)
{
ui->gl1->removeWidget(lbltest);
delete lbltest;
lbltest = NULL;
}
if (lbltest2 != NULL)
{
ui->gl1->removeWidget(lbltest2);
delete lbltest2;
lbltest2 = NULL;
}
if (lbltest != NULL)
{
ui->gl1->removeWidget(lbltest);
delete lbltest;
lbltest = NULL;
}
if (lbltest2 != NULL)
{
ui->gl1->removeWidget(lbltest2);
delete lbltest2;
lbltest2 = NULL;
}
To copy to clipboard, switch view to plain text mode
I was hoping the mainwindow would shrink back to its original size, but instead, the original widgets expand into the additional space. At this point I can manually resize by dragging the border of the mainwindow back to the original size. Is it possible to achieve this programmatically?
Bookmarks