Active Topics

 


Reply
Thread Tools
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#1
How do I remove a widget from a layout?

Code:
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    startGui = new StartScreenGUI();
    ui->verticalLayout->insertWidget(0,startGui);
}


void MainWindow::switchToStart()
{
    deleteGuis();

    startGui = new StartScreenGUI();
    ui->verticalLayout->insertWidget(0,startGui);
}
void MainWindow::deleteGuis()
{
    ui->verticalLayout->removeWidget(startGui);

    ui->verticalLayout->removeWidget(schemeGui);

    ui->verticalLayout->removeWidget(settingsGui);

    ui->verticalLayout->removeWidget(listGui);

    ui->verticalLayout->removeWidget(historyGui);
    
}
What have I done wrong here? What happens is that it just put the new widget on top on the old one. I have tried the update() function but it does not seem to do anything in this case. It works if I delete the widget but as I do not know what widget that is in the layout at the moment I have no idea how to destroy the widget as I can not delete widgets that is already deleted(program freezes)
 
Posts: 1,048 | Thanked: 979 times | Joined on Mar 2008 @ SF Bay Area
#2
Removing the widget from the layout is not enough. Hide it.
 

The Following User Says Thank You to uvatbc For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 02:10.