QListWidget自定义item实现

效果如下:
QListWidget自定义item实现
关键代码:

//添加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;
}
上一篇:寒假:Day7


下一篇:where语句的用法笔记