Is there a way to display icons in a QListView without text?

Using QListView and QStandardItemModel, is it possible to display icons in a list view without displaying related text? QStandardItem is defined like this:

QStandardItem ( const QIcon & icon, const QString & text ) 

So it seems like some kind of text string is required - I want the icon to display. If I use the following code, I get icons on demand, but I also get an empty text element below them. I do not want it.

 ImageListView->setViewMode( QListView::IconMode ); { QStandardItemModel *iStandardModel = new QStandardItemModel(this); QStandardItem* item1 = new QStandardItem(QIcon("images/shield-280x280.png"),""); QStandardItem* item2 = new QStandardItem(QIcon("images/shield-280x280.png"),""); iStandardModel->appendRow(item1); iStandardModel->appendRow(item2); ImageListView->setIconSize(QSize(100,100)); ImageListView->setUniformItemSizes(true); ImageListView->setDragDropMode(QAbstractItemView::DropOnly); ImageListView->setModel(iStandardModel); } 

If I run into the problem of creating a custom model, can I solve this problem?

+7
c ++ qt qlistview
source share
1 answer

Yes you can do it.

first you create a delegate associated with the list.Then view,

When inserting elements into the list, use the set-data function to insert the icon, and in the delegate drawing event, you process the drawing icon. I hope this is clear.

+3
source share

All Articles