效果如下:
关键代码:
//添加item
void CListTestWgt::AddItem(MarkType type, int serialNum, const QString &content)
{
CItemWidget *pItemWidget = new CItemWidget(this);
pItemWidget->SetData(type, serialNum, content);
QListWidgetItem *pItem = new QListWidgetItem();
if (type == ellipse)
pItem->setSizeHint(QSize(350, 110));
else
pItem->setSizeHint(QSize(350, 55));
ui->listWidget->addItem(pItem);
ui->listWidget->setItemWidget(pItem, pItemWidget);
connect(pItemWidget, SIGNAL(sgnDeleteItem()), this, SLOT(sltDeleteItem()));
}
//删除item
void CListTestWgt::sltDeleteItem()
{
QPoint pPoint = ui->listWidget->mapFromGlobal(QCursor::pos());
auto item = ui->listWidget->itemAt(pPoint);
ui->listWidget->removeItemWidget(item);
delete item;
}