Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't remove widget from layout
Qt 6.12 LTS is out! See what's new in the release blog

Can't remove widget from layout

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 949 Views 1 Watching
  • 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.
  • E Offline
    E Offline
    El3ctroGh0st
    wrote on last edited by
    #1

    Hey,

    so I have this piece of code:

    void VideoSettings::togglePlaylist(int playlist)
    {
        if(playlist == 1)
        {
            if(pSettings == nullptr)
                pSettings = new PlaylistSettings(this);
            ui->playlistLayout->addWidget(pSettings);
        }
        else
        {
            ui->playlistLayout->removeWidget(pSettings);
        }
    }
    

    So, I do manage to make it add the new widget. However, for some reason it doesn't remove it from the layout if playlist is not equal to one (I've made a test with QDebug and it does arrive at that part of the code, so that's not the problem). Anyone knows what could be wrong?

    raven-worxR 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      This is a highly unusual way to manage this. usually you just insert the widget in the layout and then call setVisible with true or false to show/hide it

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • E El3ctroGh0st

        Hey,

        so I have this piece of code:

        void VideoSettings::togglePlaylist(int playlist)
        {
            if(playlist == 1)
            {
                if(pSettings == nullptr)
                    pSettings = new PlaylistSettings(this);
                ui->playlistLayout->addWidget(pSettings);
            }
            else
            {
                ui->playlistLayout->removeWidget(pSettings);
            }
        }
        

        So, I do manage to make it add the new widget. However, for some reason it doesn't remove it from the layout if playlist is not equal to one (I've made a test with QDebug and it does arrive at that part of the code, so that's not the problem). Anyone knows what could be wrong?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by raven-worx
        #3

        @El3ctroGh0st said in Can't remove widget from layout:

        for some reason it doesn't remove it from the layout

        on what test is your assumption based?
        I guess you are confused that you still see it in the parent widget?
        After removing the widget from the layout it is still a child of the parent widget (as also stated in the docs)
        So you either need to hide it and/or give it a new parent widget.

        If you want to show the widget again, you do not need to remove it from the layout, but just toggle it's visibility (show()/hide()).

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        5

        • Login

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