• 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();
    }

5.listview(QStringList QStringListModel)的更多相关文章

  1. Qt 学习之路:QStringListModel

    上一章我们已经了解到有关 list.table 和 tree 三个最常用的视图类的便捷类的使用.前面也提到过,由于这些类仅仅是提供方便,功能.实现自然不如真正的 model/view 强大.从本章起, ...

  2. qt model/view 架构自定义模型之QStringListModel

    # -*- coding: utf-8 -*- # python:2.x #QStringListModel #QStringListModel 是最简单的模型类,具备向视图提供字符串数据的能力. # ...

  3. QLineEdit 自动完成(使用setCompleter,内含一个ListView)

    -------------------------------------CompleteLineEdit.h------------------------------------- #ifndef ...

  4. (二)使用预定义模型 QStringListModel例子

    使用预定义模型 QStringListModel例子 源代码如下 Main.cpp #include <QApplication> #include "teamleadersdi ...

  5. Qt 学习之路 2(43):QStringListModel

    Qt 学习之路 2(43):QStringListModel 豆子 2013年2月13日 Qt 学习之路 2 38条评论 上一章我们已经了解到有关 list.table 和 tree 三个最常用的视图 ...

  6. QT QStringListModel 示例代码

    1.  QStringListModel , 实现 插入 删除 编辑 list,支持鼠标双击编辑. 2. dialog.h #ifndef DIALOG_H #define DIALOG_H #inc ...

  7. PyQt(Python+Qt)学习随笔:model/view架构中的QStringListModel

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.QStringListModel介绍 QStringListModel是Qt提供的一个已经实现Q ...

  8. PyQt学习随笔:ListView控件的视图和数据模型分离案例

    Qt 中view类控件的目的是实现数据和模型分离,控件展示数据,数据保存在数据存储中,数据存储中的数据改变了,则控件中展示的数据跟随改变.当设计时只指定了一个控件和一个数据存储关联时,这种分离虽然也能 ...

  9. PyQt学习随笔:QtDesigner ListView控件列表项的初始化

    在QtDesigner中设计的界面中添加ListView控件后,是没办法添加需要在ListView控件中显示的列表项.由于ListView控件只是一个展示列表项的视图控件,实现了界面与数据的分离,其要 ...

随机推荐

  1. Windows 文件自动同步共享工具

    操作地址: http://blog.sina.com.cn/s/blog_1320088ed0102uxln.html下载地址: http://www.zisync.com/download

  2. hiho一下 第172周

    题目1 : Matrix Sum 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given an N × N matrix. At the beginn ...

  3. canvas的常用api

    canvas 标签 <canvas width="600" height="400" id="canvas"></canv ...

  4. IE不支持 ES6 Promise 对象的解决方案

    * 引入bluebird.js即可完美解决. /*ie兼容 Promise*/ isIE(); function isIE() { //ie? if ( !! window.ActiveXObject ...

  5. (转)Java进阶java int与Integer的区别

    Java进阶java int与Integer的区别 前言 int与Integer的区别从大的方面来说就是基本数据类型与其包装类的区别: int 是基本类型,直接存数值,而Integer是对象,用一个引 ...

  6. android系统源码下载

    ubuntu 安装git curl python 确保主目录下有一个 bin/ 目录,并且该目录包含在路径中: mkdir ~/bin PATH=~/bin:$PATH   下载 Repo 工具,并确 ...

  7. Python 之 风格规范(Google )

    开头先mark一下网址:goole官网 任何语言的程序员,编写出符合规范的代码,是开始程序生涯的第一步. 一.分号 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 二.行长度 每行不超过80个 ...

  8. Bootstrap3 学习笔记

    图片新窗口打开浏览

  9. MongoDB_聚合

    MongoDB提供以下聚合工具来对数据进行操作:聚合框架.MapReduce以及几个简单聚合命令:count.distinct.group 聚合框架:可以使用多个构件创建一个管道,上一个构件的结果传给 ...

  10. Centos7安装keepalived(自定义路径安装)-高级篇

    0.Keepalived介绍 Keepalived是一个基于VRRP协议来实现的服务高可用方案,可以利用其来避免IP单点故障,类似的工具还有heartbeat.corosync.pacemaker.但 ...