// QListWidet 添加和删除 item
void MainWindow::on_btnAddItem_clicked()
{
QString strItem = ui->lineEdit->text();
QListWidgetItem *item = new QListWidgetItem;
item->setText(strItem);
ui->listWidget->addItem(item);
}
void MainWindow::on_btnDelItem_clicked()
{
QListWidgetItem *item = ui->listWidget->takeItem(ui->listWidget->currentRow());
delete item;
}
// QListWidet 单击 和 双击事件
this->connect(ui->listWidget,SIGNAL(itemClicked(QListWidgetItem *)),this,SLOT(itemClickedSlot(QListWidgetItem *)));this->connect(ui->listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)),this,SLOT(itemDbClickedSlot(QListWidgetItem *)));
void MainWindow::itemClickedSlot(QListWidgetItem *item)
{
QMessageBox::information(this,"","click" + item->text());
}
void MainWindow::itemDbClickedSlot(QListWidgetItem *item)
{
QMessageBox::information(this,"","Dbclick" + item->text());
}