#include "qtguiapptest.h"
#include "ui_qtguiapptest.h"
QtGuiAppTest::QtGuiAppTest(QWidget *parent)
: QWidget(parent)
, ui(new Ui::QtGuiAppTest)
{
ui->setupUi(this);
//为列表添加三行
ui->listWidget->addItems(QStringList() << "张三" <<
"李四" <<
"王五" <<
"张五" <<
"刘三一"
);
//将按钮与槽函数连接起来
connect(ui->pushButton, &QPushButton::clicked, this, &QtGuiAppTest::SlotTestFindItem);
}
QtGuiAppTest::~QtGuiAppTest()
{
delete ui;
}
void QtGuiAppTest::SlotTestFindItem()
{
//获取linedit中要查找的字符串
QString str = ui->lineEdit->text();
//在列表中查找匹配的行,采用精确查找
QList<QListWidgetItem*> lstItems = ui->listWidget->findItems(str, Qt::MatchContains);
//在label中展示查找到的结果
QString text;
for(auto& it : lstItems)
{
text += it->data(Qt::DisplayRole).toString();
text += "\n";
}
ui->label->setText(text);
}
QT+QListWidget实现列表数据查询代码示例+详细注释
需积分: 0 37 浏览量
2024-04-16
17:30:42
上传
评论
收藏 47KB ZIP 举报
懒人空想家
- 粉丝: 141
- 资源: 4
最新资源
- 自动驾驶定位系列教程十:闭环修正.pdf
- HM2333-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- Python实现插入排序算法(源代码)
- 123.cpp
- HM2319-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- modbus4j-3.0.4.jar
- 蒙特·卡罗实验、使用蒙特·卡罗方法计算圆周率近似值.docx
- HM2319A-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- JAVA SpringBoot 集成华为云OBS,多镜像配置settings
- 一个文件共享系统,包括前端文件展示系统和后台管理系统,基于SpringBoot + MyBatis实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈