1、概述
Qt 模型视图(系列文章)
Qt Model/View
Qt Model/View教程
QAbstractItemModel、QAbstractListModel、QAbstractTableModel、QStringListModel、QStandardItemModel、QFileSystemModel、QSqlQueryModel、QSqlTableModel、QSqlRelationalTableModel
![](https://img-blog.csdnimg.cn/548e1e5868cd4681955e5bb16a2f2052.png)
![](https://img-blog.csdnimg.cn/c49f93199001439e92792fa2faf35ba9.png)
![](https://img-blog.csdnimg.cn/27d4564fbe884586a9305d519ec4aca9.png)
![](https://img-blog.csdnimg.cn/01da1874b31e48609a80ec465be0b8b4.png)
2、框架介绍
2.1 QStandardItemModel、QStandardItem
QStandardItemModel:管理更复杂的树结构件,其中每一个项目可以包含任意数据。
2.2 QModelIndex 索引
QModelIndex index = model->index(row, column, parent);
2.3 QItemSelectionModel 选择
2.4、QAbstractItemDelegate 代理
3、QTableView
qtablewidget解决加载百万条数据卡顿(不会存在内存溢出,界面也不会卡顿)动态加载
QTableView与QAbstractTableModel的使用
QTableView点击表头排序
QAbstractTableModel基本使用:数据展示与编辑
QAbstractTableModel基本使用:数据加载以及增删行列
QAbstractTableModel基本使用:表头相关接口
QAbstractTableModel基本使用:排序相关接口
QStyledItemDelegate基本使用:单元格数据渲染与编辑
设置tableView的时候,需要牢记先设置公共属性,然后设置model,然后才能设置列宽,否则列宽不会生效。
imp->tableView = new QTableView(this);
imp->tableView->resize(850, 200);
imp->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); //Stretch
imp->tableView->horizontalHeader()->setDefaultSectionSize(35);
imp->tableView->verticalHeader()->setDefaultSectionSize(20);
imp->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
imp->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
imp->tableView->horizontalHeader()->setStyleSheet("QHeaderView::section {color: black ;border: 1px solid #660000;}");
imp->tableView->verticalHeader()->hide();
imp->tableView->setFont(font);
m_myModel = new MyModel(this);
imp->tableView->setModel(m_myModel);
connect(m_myModel, SIGNAL(editCompleted(const QString&)), this, SLOT(setWindowTitle(const QString&)));
imp->tableView->show();