Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [.UI/FORM] How to Remove Elements fram the layout?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.2k Views
  • 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 Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    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
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

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

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        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
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #4

          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
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            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
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #6

              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
              0
              • D Offline
                D Offline
                dcbasso
                wrote on last edited by
                #7

                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
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #8

                  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
                  0
                  • D Offline
                    D Offline
                    dcbasso
                    wrote on last edited by
                    #9

                    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
                    0
                    • M Offline
                      M Offline
                      mlong
                      wrote on last edited by
                      #10

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved