Deleting "created" pushbuttons in runtime.

  • for(int i=0; i<row; i++)
          for(int j=0; j<column; j++)
              view[k] = new QGraphicsView(this->centralWidget());//this->centralWidget
              _instance = new VlcInstance(VlcCommon::args(), this);
              _player[k] = new VlcMediaPlayer(_instance);
              video[k] = new VlcWidgetVideo(this->centralWidget()); //cntralWidget in bracket
              p1[k]=new QPushButton("pushbutton");
              p2[k]=new QPushButton("pushbutton");
              label[k]=new QLabel("Mitesh");
              layout1[k]=new QHBoxLayout;
              layout[k]=new QVBoxLayout;
              case 0:
    /* more code here */

    As shown in code I have created p1[k] , p2[k], and label[k] widgets.
    But in some cases I dont need them. How to remove extra widgets.

  • Hi,

    you can hide a unused widget by using the function hide() or setVisible(false)



  • I can not find hide or setvisible function for layout.
    I can only hide pushbuttons.

  • Qt Champions 2017

    Yes, you cannot hide a layout.
    You must hide the unused buttons.

    If you decide to really remove them, there is ONLY one way and its via

    That give you back your button so you own it again. else layout still owns it and u are not allowed to delete it.

  • Moderators

    @mrjj said in Deleting "created" pushbuttons in runtime.:

    Yes, you cannot hide a layout.

    But the layouts parent widget though. (QLayout::parentWidget())
    Which is the widget it has to been installed on when the layout is visible.

  • For me, the simplest way is to create a standard QWidget. Layout1[k] will become the layout of this QWidget. So you will be able to show/hide this widget using setVisible on it.

Log in to reply

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