Delete widgets from QVBoxLayout



  • Hi,
    I am creating a QWidget in the constructor and adding that QWidget to QScrollArea. When the verticall scroll bar reaches to the maximum value, i am creating another QWidget and adding to the existing widget. All these are in vertical layout.

    I want to delete all the widgets in the vertical layout created dynamically when i press a button.

    My code :

    @writingArea is a another class.
    writingArea::writingArea(QWidget *parent) :
    QWidget(parent){ //constructor of writingArea class//}

    //Declaration
    MainWindow.h

    writingArea *writewidget;
    QVBoxLayout *vwritelayout;

    //Constructor of MainWindow.h

    writewidget = new writingArea;
    writewidget->setMinimumSize(1000,1300);
    vwritelayout->addWidget(writewidget);
    connect(ui->answerarea_scrollArea->verticalScrollBar(),SIGNAL(actionTriggered(int)), this,SLOT(add_write_area()));
    connect(ui->pushbutton,SIGNAL(clicked()),this,SLOT(delete_wid gets()));

    //Functions
    void MainWindow::add_write_area()
    {

    int write_sliderval = ui->answerarea_scrollArea->verticalScrollBar()->maximum();
    int write_sliderpos=ui->answerarea_scrollArea->verticalScrollBar()->sliderPosition();

    if(write_sliderval == write_sliderpos)
    {
    writewidget = new writingArea;
    writewidget->setMinimumSize(1000,1300);
    vwritelayout->addWidget(writewidget);
    }
    }
    void Mainwindow::delete_widgets()
    {

    //Here I want to delete the widgets created in veritelayout.

    }@

    Please help me....


  • Lifetime Qt Champion


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.