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. Can't seem to remove Qlabel widgets from QGridLayout
Forum Updated to NodeBB v4.3 + New Features

Can't seem to remove Qlabel widgets from QGridLayout

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.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.
  • M Offline
    M Offline
    macka601
    wrote on last edited by
    #1

    Hi All,

    I'm a definite newbie, so hopefully i make sense. (think too i'm on 4.7)

    What i'm trying to do is sort of based on "this":http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/qtconcurrent-imagescaling-imagescaling-cpp.html
    I created a form with a QScrollArea, and added a QGridLayout to it. Then Like the example i added a number of QLabels to the QGridLayout.
    I then rescale my images, and assign them to the Qlabels created.

    Problem is that when i go back and choose another lot of images, it then stacks the new images behind the current ones.

    So what i thought was - easy, just Delete/remove the QLabels in the QGridLayout before adding.

    So - i search around and the best i seem to come up with was
    @void MainWindow::clearLayout(QLayout *layout)
    {
    QLayoutItem *item;

    while((item = layout->takeAt(0)))
    {
        if (item->layout())
        {
            clearLayout(item->layout());
            delete item->layout();
        }
    
        if (item->widget())
        {
            delete item->widget();
        }
    }
    

    }@

    So i have a clear button that calls this function. So i load my images, then hit the clear button, and load some more, and the program crashes.

    So my question is, is this the right way to remove widgets from my QGridLayout? Or should i not be removing them? is there a better way?

    Thanks
    Grant

    1 Reply Last reply
    0
    • S Offline
      S Offline
      scroverty
      wrote on last edited by
      #2

      I think you would need a "new" for every "delete" you make.

      Alvis Ar'Berkeley Andrew.
      Pleased to meet you!

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

        Thanks for that, Every time i create the widgets i add a new one? using...
        @
        for(i = 0; i < imagesFound.count();i++)
        {
        QLabel* scaledImageLabel = new QLabel;

            ui->thumbListView->addWidget(scaledImageLabel, x, y);
        
            imageLabels.append(scaledImageLabel);
        
            if(++y >= 3)
            {
                y = 0;
                x++;
            }
        }
        

        @

        So to me (i could be wrong), I use the new to create the QLabel? so there's always a new one?

        Thanks
        Grant

        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