有没有一种方法可以在没有文本的QListView中显示图标? [英] Is there a way to display icons in QListView without text?
问题描述
使用QListView和QStandardItemModel,可以在列表视图中显示图标而不显示相关文本吗? QStandardItem的定义如下:
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?
推荐答案
是的,可以做到.
首先,创建与列表视图关联的委托.然后,
first you create a delegate associated with the list-view.Then,
在将元素插入到列表视图时,请使用set-data函数插入图标,并在委托的paint事件中处理图形图标.我希望一切都清楚.
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.
这篇关于有没有一种方法可以在没有文本的QListView中显示图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!