[.UI/FORM] How to Remove Elements fram the layout?



  • Hello , me again...
    I'm add a QWidget dinamically to my layout. Now I'm trying to remove this same element and I could not do that... I search for code, read the doc and make a test drive desing and still coun't remove this QWidget...

    How can I do so?


  • Moderators

    Have a look at "this thread":http://qt-project.org/forums/viewthread/4926


  • Moderators

    QLayout::removeWidget()? Or perhaps just deleting the widget?



  • I make this code:

    @
    void MainWindow::clearScreen()
    {
    ui->contentWidget-layout()->removeWidget( currentWidget );
    // ui->contentLayout->removeItem( ui->contentLayout->itemAt(0) ); //THIS NOT WORKS TOO
    }
    @

    @
    void MainWindow::changeCurrentScreen(QWidget *newScreen)
    {
    currentWidget = newScreen;
    ui->contentLayout->addWidget( newScreen );
    }
    @


  • Moderators

    Removing a widget from a layout does not remove it from the screen. See the thread that Eddy linked to, above.



  • Eddy, works for me removing the pointer to the Widget, but is this the best or maybe the correct way to resolve this problem?

    Thanks



  • Another question... if I setParent(0); the QWidget is removed... OK!
    If i have same object and I setAgain the right parent they will apper again in the last "state" that when I remove the parent?


  • Moderators

    Would "QWidget::hide()":/doc/qt-4.8/qwidget.html#hide suit you better instead? What is your use case for wanting to remove or add widgets?



  • mlong... It's hard to me explain to you what I need... but my application will have a lot of screens and depends on the side menu bar (similar to Qt Creator) the main screen of my app will show the recurses (in Qt Create it's similar to the code editor, Desing, projects screens...)

    Did you understand?

    The method hide() works too...


  • Moderators

    Take a look at "QStackedWidget":/doc/qt-4.8/qstackedwidget.html. Maybe that might save you some effort.

    Edit: Or possibly "QStackedLayout":/doc/qt-4.8/qstackedlayout.html


Log in to reply
 

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