void QListWidget::setItemWidget(QListWidgetItem * item, QWidget * widget)
关键代码:
//图片换成目录图标就能够
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QListWidget *listWidget = new QListWidget();
listWidget->setSpacing(10);
listWidget->setViewMode(QListView::IconMode);
listWidget->setIconSize(QSize(100,100));
QPixmap pix1(QString(":/list/image/1.jpg"));
QPixmap pix2(":/list/image/2.jpg");
QListWidgetItem *item1 = new QListWidgetItem(QIcon(pix1.scaled(QSize(100,100))),"picture1");
QListWidgetItem *item2 = new QListWidgetItem(QIcon(pix2.scaled(QSize(100,100))),"picture2");
QLineEdit* line = new QLineEdit; //创建部件
listWidget->addItem(item1);
listWidget->addItem(item2); //先加入项目
item1->setSizeHint(QSize(100,120));
item2->setSizeHint(QSize(100,120));
listWidget->setItemWidget(item2,line); //加入部件
// listWidget->removeItemWidget(item2);
listWidget->show();
app.exec();
return 0;
}