Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    3
    10
    2759
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dcbasso last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • E
        Eddy last edited by

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

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply Reply Quote 0
        • M
          mlong last edited by

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

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply Reply Quote 0
          • D
            dcbasso last edited by

            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 );
            }
            @

            1 Reply Last reply Reply Quote 0
            • M
              mlong last edited by

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

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply Reply Quote 0
              • D
                dcbasso last edited by

                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

                1 Reply Last reply Reply Quote 0
                • D
                  dcbasso last edited by

                  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?

                  1 Reply Last reply Reply Quote 0
                  • M
                    mlong last edited by

                    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?

                    Software Engineer
                    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                    1 Reply Last reply Reply Quote 0
                    • D
                      dcbasso last edited by

                      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...

                      1 Reply Last reply Reply Quote 0
                      • M
                        mlong last edited by

                        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

                        Software Engineer
                        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post