Can't seem to remove Qlabel widgets from QGridLayout
-
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 -
I think you would need a "new" for every "delete" you make.
-
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