How to add Icons to items using QAbstractListModel in QListView
Hi All:
I don't know how to add Icons to items using QAbstractListModel in QListView ,
Is anybody know how to ?
Thanks for your suggestions.
Re: How to add Icons to items using QAbstractListModel in QListView
Re: How to add Icons to items using QAbstractListModel in QListView
Quote:
Originally Posted by
caduel
I don't understand anything you wrote.
Can you post some example code here?
Re: How to add Icons to items using QAbstractListModel in QListView
Hey
You can set an icon with one of the QAbstractItem::setData overloaded methods.
Example:
Code:
item
->setData
(QIcon("icon.png"),Qt
::DecorationRole);
Re: How to add Icons to items using QAbstractListModel in QListView
you can see many easy examples in qt assistant....
search for "model/view" topics
Re: How to add Icons to items using QAbstractListModel in QListView
Are you able to return text from the model ?
If yes, you must do it with Qt::DisplayRole.
Similary theres Qt::DecorationRole.. thats what caduel said
1 Attachment(s)
Re: How to add Icons to items using QAbstractListModel in QListView
Code:
ui.
contentListView->setViewMode
(QListView::IconMode);
QList<QStandardItem*> *items = new QList<QStandardItem*> ();
QString qs
= ui.
searchLineEdit->text
();
*items = getItemsToDisplay(qs);
iStandardModel->appendColumn(*items);
//Setting the icon size
ui.
contentListView->setIconSize
(QSize(128,
128));
//Setting the model
ui.contentListView->setModel(iStandardModel);
In ui_GUIClass.h:
In GUIClass.h:
The result is in attached sample.jpg.
Hope, this helps.