Qt World Summit: Register Today!


How to clear all widgets in QScrollArea ?



  • Why I can not clear all widgets in QScrollArea ?

    QLabel *label = new QLabel;
    label->setText("FIFA");
    ui->verticalLayout_shedule->addWidget(label,0,Qt::AlignTop);
    ...
    QLayoutItem *child;
    while ((child = ui->verticalLayout_shedule->takeAt(0)) != 0) {
        delete child;
    }
    

    alt text


  • Lifetime Qt Champion

    Hi
    You only take the items out.
    the items also contains the actual widget.

    void MainWindow::on_toolButton_released()
    {
        QLayoutItem *child;
        while ((child = ui->verticalLayout->takeAt(0)) != 0) {
            delete child->widget(); // get rid of widget too
            delete child;
        }
    }
    
    

Log in to reply