42 lines
791 B
C++
42 lines
791 B
C++
#include "form5.h"
|
|
#include "ui_form5.h"
|
|
|
|
Form5::Form5(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::Form5)
|
|
{
|
|
ui->setupUi(this);
|
|
}
|
|
|
|
Form5::~Form5()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void Form5::on_addBtn_clicked()
|
|
{
|
|
ui->listWidget->addItem(ui->lineEdit->text());
|
|
|
|
}
|
|
|
|
void Form5::on_getBtn_clicked()
|
|
{
|
|
QString selectedContent = ui->listWidget->currentItem()->text();
|
|
QMessageBox::information(this,"选中",selectedContent);
|
|
}
|
|
|
|
void Form5::on_clearBtn_clicked()
|
|
{
|
|
ui->listWidget->clear();
|
|
}
|
|
|
|
void Form5::on_delBtn_clicked()
|
|
{
|
|
// currentItem() 获取当前选定的项目
|
|
QListWidgetItem *item = ui->listWidget->currentItem();
|
|
// takeItem() 通过索引删除行
|
|
ui->listWidget->takeItem(ui->listWidget->row(item));
|
|
|
|
delete item; //释放项目所占的内存
|
|
}
|