Results 1 to 2 of 2

Thread: How to add items dynamically to QListWidget?

  1. #1
    Join Date
    Mar 2009
    Location
    india->gujarat->bhavnagar
    Posts
    36
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Question How to add items dynamically to QListWidget?

    i have to load certain image as icon in Qlistwidget but everytime to perform this operation i have to write
    Qt Code:
    1. ui->listWidget_2->addItem(new QListWidgetItem(QIcon(":/new/Myresource/Tulips.jpg"),"Tulips"));
    To copy to clipboard, switch view to plain text mode 
    can i perform this opeartion dynamically ?? so that everytime i dont need to write same code for loading all images.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to add items dynamically to QListWidget?

    You could do something like
    Qt Code:
    1. QStringList myItems = (QStringList() << "Tulips" << "Roses" << "Lillies");
    2. foreach (const QString &item, myItems)
    3. ui->listWidget_2->addItem(new QListWidgetItem(QIcon(QString(":/new/Myresource/%1.jpg").arg(item), item));
    To copy to clipboard, switch view to plain text mode 
    Is that what you're looking for?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Replies: 1
    Last Post: 29th November 2010, 18:22
  2. Replies: 2
    Last Post: 28th September 2010, 11:34
  3. adding items in scroll area dynamically
    By Ezhil in forum Qt Programming
    Replies: 5
    Last Post: 22nd May 2009, 17:33
  4. Problem in enabling QtreeWidget items dynamically
    By jyoti kumar in forum Qt Programming
    Replies: 10
    Last Post: 7th June 2006, 19:10
  5. Getting all items of a QListWidget
    By Codepoet in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2006, 23:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.