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 data from a QScrollArea

Deleting data from a QScrollArea

Scheduled Pinned Locked Moved Solved General and Desktop
qscrollarea
16 Posts 2 Posters 10.6k 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.
  • mrjjM mrjj

    @mar0029 said:
    ok, its hard to visualize what u put in to what ;)

    Have you tried making a brand version and simply replace it ?
    scrollArea->setWidget(myWidgetNo2);

    M Offline
    M Offline
    mar0029
    wrote on last edited by
    #5

    @mrjj I made a diagram as to what I've created. I'm creating a lot of the QHBoxLayouts within QVBoxLayout.

    mrjjM 1 Reply Last reply
    1
    • M mar0029

      @mrjj I made a diagram as to what I've created. I'm creating a lot of the QHBoxLayouts within QVBoxLayout.

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

      @mar0029
      That is super.
      So its the "red" ones you are trying to replace?

      Also, can u just replace Widget holding all the reds,?
      or you do u need to keep some of them?

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        @mar0029
        That is super.
        So its the "red" ones you are trying to replace?

        Also, can u just replace Widget holding all the reds,?
        or you do u need to keep some of them?

        M Offline
        M Offline
        mar0029
        wrote on last edited by
        #7

        @mrjj Thank you! I used a ruler and everything!

        I would like to keep everything up to the red a.k.a. my QVBoxLayout
        What happens to all of the QHboxLayout and all the widgets within those Layouts, I don't care.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

          Hmm.
          Ok. I was kinda planning
          to just create new widget with a boxlayout and call
          setWidget on ScrollArea.
          But u say this crashes?

          M 1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #9

            Hi again
            i made same layout in designer
            I kill them this way

            
            void MainWindow::on_btremove_released() {
            
              QList<QWidget*> allSubLayouts = ui->innerwidget->findChildren<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
              int size = allSubLayouts.size();
              // take all out
              while (( ui->innerwidget->layout()->takeAt(0)) != 0)
                // killem
                for(int i = 0; i < size; i++) {
                  qDebug() << allSubLayouts[i]->metaObject()->className();
                  delete allSubLayouts[i];
            
                }
            
            
            }
            
            

            U can check your self.
            https://www.dropbox.com/s/auivviiv8tv7jfw/myscroll.zip?dl=0
            should be the same you want if i read ur fine drawing correct :)
            Note the Qt::FindDirectChildrenOnly flag!

            M 1 Reply Last reply
            0
            • mrjjM mrjj

              Hmm.
              Ok. I was kinda planning
              to just create new widget with a boxlayout and call
              setWidget on ScrollArea.
              But u say this crashes?

              M Offline
              M Offline
              mar0029
              wrote on last edited by
              #10

              @mrjj
              I don't want to delete my QWidget because I would have to dynamically create a new one each time I loaded a new file and I really don't want to deal with that.

              I'm making some progress with this:

                  while((child = mainVbox->layout()->takeAt(0)) != 0)
                      {
                      delete child;
                      }
              

              but in the documentation it says that when I delete a layout, I have to delete the widgets separately.
              So I'm trying to make a list of the widgets found within the sublayout and then delete from there but it's not working.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #11

                Did u try the sample?
                It leaves the QWidget and layout but kills all it members.

                M 1 Reply Last reply
                0
                • mrjjM mrjj

                  Hi again
                  i made same layout in designer
                  I kill them this way

                  
                  void MainWindow::on_btremove_released() {
                  
                    QList<QWidget*> allSubLayouts = ui->innerwidget->findChildren<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
                    int size = allSubLayouts.size();
                    // take all out
                    while (( ui->innerwidget->layout()->takeAt(0)) != 0)
                      // killem
                      for(int i = 0; i < size; i++) {
                        qDebug() << allSubLayouts[i]->metaObject()->className();
                        delete allSubLayouts[i];
                  
                      }
                  
                  
                  }
                  
                  

                  U can check your self.
                  https://www.dropbox.com/s/auivviiv8tv7jfw/myscroll.zip?dl=0
                  should be the same you want if i read ur fine drawing correct :)
                  Note the Qt::FindDirectChildrenOnly flag!

                  M Offline
                  M Offline
                  mar0029
                  wrote on last edited by
                  #12

                  @mrjj oh my where did you find that flag? How did you know you could do ui->innerWidget->findChildren<QWidget*>(String(), Qt::FindDirectChildrenOnly); ??

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Did u try the sample?
                    It leaves the QWidget and layout but kills all it members.

                    M Offline
                    M Offline
                    mar0029
                    wrote on last edited by
                    #13

                    @mrjj Thank you for your help. I am unable to get it to work right now but I can see this achieving the goal. I will come back to it later today/tomorrow.

                    Thanks again!

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      Hi
                      In the documentation for findChildren. I went looking as your
                      drawing made it very clear what u wanted. (kill all inner widgets)

                      So If you do it for your Widget (myWidget), it should do the same.
                      ( i hope :)

                      you are welcome. I hope u get it to work.

                      M 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        Hi
                        In the documentation for findChildren. I went looking as your
                        drawing made it very clear what u wanted. (kill all inner widgets)

                        So If you do it for your Widget (myWidget), it should do the same.
                        ( i hope :)

                        you are welcome. I hope u get it to work.

                        M Offline
                        M Offline
                        mar0029
                        wrote on last edited by
                        #15

                        @mrjj
                        So here is what I've ended up doing.

                        I had been able to get a QList of the layouts in the main layout like so

                         QList<QLayout *> allSubLayouts = mainVbox->findChildren<QLayout *>();
                        

                        So I checked if that list was empty or not, basically seeing if it was the first time to use the program.

                        if(!allSubLayouts.empty())
                        {
                        
                            int size = allSubLayouts.size();
                            for(int i = 0; i < size; i ++)
                            {
                                qDebug() << "this is what is at allSublayouts.at("<<i<<") " << allSubLayouts.at(i);
                        
                        
                                for(int j = 0; j < allSubLayouts.at(i)->count(); ++j)
                                {
                                    QWidget *w = allSubLayouts.at(i)->itemAt(j)->widget();
                                    if(w != NULL)
                                    {
                                        w->setVisible(false);
                                    }
                                }
                            }
                        }
                        

                        Since I knew that there were layouts available, instead of using findChildren() I used allSubLayouts.at(i)->*itemAt*(j)->*widget*();

                        While this solves my problem of widgets and layouts overlapping in MainWindow, I don't know if it will cause a memory leak or will use up too much memory, since I'm not deleting any widgets/layouts.

                        1 Reply Last reply
                        0
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #16

                          Hi

                          "allSubLayouts.at(i)->*itemAt*(j)->*widget*();"
                          

                          made my brain hurt :)
                          Well since u are not deleting any widgets, u will use more and more memory,
                          but since they are still owned by layout, it will be free when application ends.

                          1 Reply Last reply
                          1

                          • Login

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