How to get visible items (or items index) from QListWidget
Hi all,
How do we get the visible items (or items index) from the QListWIdget.
Requirement is
I am displaying some 100 items in QListWIdget, each items consists of some text and image.
Now I want to set images to only visible items, and after scrolling I need to remove the those images (for the indivisible items) and again set images for the new visible items.
How do I achieve this.
Thanks,
Siddu
Re: How to get visible items (or items index) from QListWidget
Well, if you're setting a widget I suppose you could use isVisible on the set widget. If you're not setting a widget then nothing's obvious.
Re: How to get visible items (or items index) from QListWidget
Hi
Thanks,
But I did not get your point,
here is the simplified code, what iam trying
for(int index=0; index < 100; index++)
{
QListWidgetItem *item1 = new QListWidgetItem(ui->listWidget);
item1->setSizeHint(QSize(270,50));
item1->setData(Qt::DisplayRole,"Some String");
ui->listWidget->addItem(item1);
imagedownloader= new ImageDownLoader();
connect(imagedownloader,SIGNAL(imageDownloaded(int,QPixmap*)),this,SLOT(imageAvailable(int,QPixmap*)));
connect(imagedownloader,SIGNAL(errorInDownLoadingImage()),this,SLOT(imageNotAvailable()));
imagedownloader->downLoadImageAt("http://mobilitysite.com/wp-content/uploads/2009/01/iphone11.jpg");
}
Here iam setting the "some string" in displayrole, and downloading the image, as soon as I get call back from the ImageDownLoader, (i.e imag is downloaded) , I need the set that image to only visible item.
and also I need to download images for only visible items and remove the images for invisible items if it is already downloaded and set (as we scroll visible items will change).
Thanks,
Siddu
Re: How to get visible items (or items index) from QListWidget
So apparently you're not doing setItemWidget. I've never tried to get the itemWidget for a row where setItemWidget hasn't been done first -- not sure if it will return anything.
Re: How to get visible items (or items index) from QListWidget
Hi
Here is my new code
For(int index=0; index < 100; index++)
{
Cell* cell = new Cell();
cell->setParent(ui->listWidget);
cell->setTitle(item->m_Title);
cell->setDescription(item->m_ShortDescription);
cell->setImage(item->m_IconURL);
QListWidgetItem *dataItem= new QListWidgetItem(ui->listWidget);
dataItem->setSizeHint(QSize(340,100));
ui->listWidget->addItem(dataItem);
ui->listWidget->setItemWidget(dataItem,cell);
bool isVisible = ui->listWidget->isVisible();
qDebug() << "IS VISIBLE------------ : "<<isVisible;
isVisible = ui->listWidget->isVisibleTo(cell);
qDebug() << "IS VISIBLE TO ------------ : "<<isVisible;
}
Where Cell is subclass of QWidget and contains 3 labels,
cell->setTitle(item->m_Title) and cell->setDescription(item->m_ShortDescription); set the lebels text
cell->setImage(item->m_IconURL); this down loads the image for that cell (item).
Now I want to call cell->setImage(item->m_IconURL); only to visible cell (items).
Please let me know how to achieve this.
the isVisible() is giving true to all cells(items) created.
Thanks,
Siddu