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. Deleting "created" pushbuttons in runtime.
Qt 6.11 is out! See what's new in the release blog

Deleting "created" pushbuttons in runtime.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 3.1k 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.
  • mit_cruzeM Offline
    mit_cruzeM Offline
    mit_cruze
    wrote on last edited by kshegunov
    #1
    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
              view[k]->setViewport(video[k]);
              _player[k]->setVideoWidget(video[k]);
              _equalizerDialog->setMediaPlayer(_player[k]);
    
              p1[k]=new QPushButton("pushbutton");
              p2[k]=new QPushButton("pushbutton");
              label[k]=new QLabel("Mitesh");
    
    
              layout1[k]=new QHBoxLayout;
              layout1[k]->addWidget(label[k]);
              layout1[k]->addWidget(p1[k]);
              layout1[k]->addWidget(p2[k]);
              
              
              layout[k]=new QVBoxLayout;
              layout[k]->addLayout(layout1[k]);
              layout[k]->addWidget(view[k]);
              
              switch(flag1)
              {
              case 0:
    
                  gridLayout->addLayout(layout[k],i,j,1,1);
                  break;
    /* 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.

    A 1 Reply Last reply
    0
    • C Offline
      C Offline
      Corvus91
      wrote on last edited by
      #2

      Hi,

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

      Greetings,

      Corvus

      1 Reply Last reply
      0
      • mit_cruzeM Offline
        mit_cruzeM Offline
        mit_cruze
        wrote on last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • mit_cruzeM mit_cruze

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @mit_cruze
          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
          takeAt
          http://doc.qt.io/qt-5/qlayout.html#takeAt

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

          raven-worxR 1 Reply Last reply
          0
          • mrjjM mrjj

            @mit_cruze
            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
            takeAt
            http://doc.qt.io/qt-5/qlayout.html#takeAt

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

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

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

            --- 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
            0
            • mit_cruzeM mit_cruze
              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
                        view[k]->setViewport(video[k]);
                        _player[k]->setVideoWidget(video[k]);
                        _equalizerDialog->setMediaPlayer(_player[k]);
              
                        p1[k]=new QPushButton("pushbutton");
                        p2[k]=new QPushButton("pushbutton");
                        label[k]=new QLabel("Mitesh");
              
              
                        layout1[k]=new QHBoxLayout;
                        layout1[k]->addWidget(label[k]);
                        layout1[k]->addWidget(p1[k]);
                        layout1[k]->addWidget(p2[k]);
                        
                        
                        layout[k]=new QVBoxLayout;
                        layout[k]->addLayout(layout1[k]);
                        layout[k]->addWidget(view[k]);
                        
                        switch(flag1)
                        {
                        case 0:
              
                            gridLayout->addLayout(layout[k],i,j,1,1);
                            break;
              /* 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.

              A Offline
              A Offline
              Alain38
              wrote on last edited by
              #6

              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.

              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