When removing from layout the widget is not fully removed


  • Banned

    when i am removing widget from QGridLayout, the widget is removed from the corresponding row and column but it is still there on the screen. How to remove it completely.

    [code]
    QWidget *cent = new QWidget(this);
    cent->resize(1000,800);
    setCentralWidget(cent);
    QTextEdit *list[3][3];
    QGridLayout *layout = new QGridLayout(cent);
    for(int row=0; row<3; row++)
    {
    for(int col=0; col<3; col++)
    {
    QTextEdit *text = new QTextEdit(cent);
    text->resize(200,100);
    list[row][col] = text;
    layout->addWidget(list[row][col],row,col);
    }
    }
    cent->setLayout(layout);
    layout->removeWidget(list[1][1]);
    [/code]
    please help



  • bq. Removes the widget widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout.
    Note: The ownership of widget remains the same as when it was added

    If you want the widget to be deleted, you need to delete it yourself:
    @ QTextEdit * widget = list[1][1];
    widget->deleteLater();@

    Or if you only want to hide it:
    @widget->hide();@


Log in to reply
 

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