最后再给出经过@XChinux点拨之后的最佳实践:
在添加项的位置:
QStandardItem *myFrends = new QStandardItem;
myFrends->setData(itemname, Qt::DisplayRole);
myFrends->setData(itemname, Qt::UserRole + 1);
myFrends->setData(imgpath, Qt::UserRole + 2);
myFrends->setSizeHint(QSize(280, 60));
parentItem->appendRow(myFrends);
在重写的委托的paint方法里面通过以下代码获取:
QString imgpath = index.model()->data(index, Qt::UserRole+2).toString();
qDebug() << imgpath;