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

北城余情 提交于 2019-12-04 21:44:15

问题


Using a QListView, and QStandardItemModel, is it possible to display icons in the list view without displaying the associated text? QStandardItem is defined as so:

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

So it seems to require a text string of some sort - I only want the icon displayed. If I use the following code, I get the icons as requested, but I also get a blank text element underneath them. I don't want this.

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 go to the trouble of building a custom model, can I resolve this issue?


回答1:


Yes, you can do.

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

While inserting the elements to the listview, use set-data function to insert the icon and in the paint event of delegate you handle the drawing icon. i hope its clear.




回答2:


How to show icons without text in QListWidget?

from the above post, you can use NULL to get rid of that empty space



来源:https://stackoverflow.com/questions/2597534/is-there-a-way-to-display-icons-in-qlistview-without-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!