×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    32

    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

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    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.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    32

    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:isplayRole,"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

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    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.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    32

    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

Similar Threads

  1. How to add more items in QListWidget
    By siddugh in forum [Archived] Qt SDKs and Tools
    Replies: 12
    Last Post: 2011-01-03, 05:23
  2. How can i select multi items in QListWidget?
    By SaiPrasad2010 in forum Qt
    Replies: 0
    Last Post: 2010-12-28, 05:37
  3. Replies: 6
    Last Post: 2010-12-03, 14:46
  4. Multiline items in QListWidget
    By pavel_turbin in forum Qt
    Replies: 2
    Last Post: 2010-07-10, 20:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×