5.listview(QStringList QStringListModel)
2024-08-31 09:05:05
- UI
- mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <QStringListModel> namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = );
~MainWindow(); private slots:
//按下按钮
void on_pushButton_clicked();
22 //combox改变
23 void on_comboBox_currentIndexChanged(int index);
private:
Ui::MainWindow *ui;
27 //设置列表
28 QStringList *sl;
29 //设置模式,显示列表
30 QStringListModel *slm;
}; #endif // MAINWINDOW_H - mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QStringListModel> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
10 sl = new QStringList();
11 sl->append("hello1");
12 sl->append("hello2");
13 sl->append("hello3");
14 sl->append("hello4");
15 //创建字符串模式
16 slm = new QStringListModel(this);
17 slm->setStringList(*sl);
18 //显示
19 ui->listView->setModel(slm);
20
21 //设置combox选项
22 ui->comboBox->insertItem(0,"hello1","hello1");
23 ui->comboBox->insertItem(1,"hello2","hello2");
24 ui->comboBox->insertItem(2,"hello3","hello3");
25 ui->comboBox->insertItem(3,"hello4","hello4");
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::on_pushButton_clicked()
{ QString qstr;
39 qstr = ui->lineEdit->text();
40 sl->append(qstr);
41 //模式设置字符串
42 slm->setStringList(*sl);
43 //显示
44 ui->listView->setModel(slm);
} void MainWindow::on_comboBox_currentIndexChanged(int index)
{
//获取当前数据
50 QString myqstr=ui->comboBox->currentText();
51 ui->lineEdit->setText(myqstr);
} - main.cpp
#include "mainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show(); return a.exec();
}
最新文章
- MongoDB使用锦集
- CLR via C#深解笔记二 - 类型设计
- iisapp 命令 弹出 iisschlp.wsc [88,25] 属性值无效 progid
- 新手自学ABAP(1)--数据类型
- 黑马程序员_Java面向对象_内部类
- Android学习笔记27:网格视图GridView的使用
- linux下tomcat shutdown后 java进程依然存在
- python练习题-员工信息表
- 吴裕雄 03-mysql连接
- Hadoop家族学习路线、实践案例
- 最近玩Bootstrap , 一些小工具 记录在案。
- LeetCode 27 Remove Element (移除数组中指定元素)
- MNIST机器学习入门【学习笔记】
- Spring框架的事务管理的分类
- shell统计各省的百强县
- 各排序算法的Java实现及简单分析
- Linux Guard Service - 守护进程的作用、用途、父进程标识的特点
- jsp电子商务系统之六 订单篇1
- shell 获取hive表结构
- POJ:2456-Aggressive cows
热门文章
- [lua]异步串行流程*协程
- 异步lambda表达式
- T对象序列化后T对象中属性字段不见了?
- 洛谷P2607 [ZJOI2008]骑士(树形dp)
- python课程设计笔记(五) ----Resuests+BeautifulSoup (爬虫入门)
- deepin下jdk和tomcat的安装教程
- (转)Webpack2 + Vue2 + Vue-Router2 如何实现懒加载?
- 修改ElementUI源码
- hdu4009 Transfer water 最小树形图
- vue项目布局