当前位置:网站首页>QT QtableView的使用示例
QT QtableView的使用示例
2022-06-22 08:00:00 【Licht小粉】
1——创建表格内容
QStandardItemModel* m_standardItemModel = new QStandardItemModel(this);
QStandardItem *item = new QStandardItem(“李四”);
m_standardItemModel->setItem(i,j,item);//行、列、元素
tableView->setModel(m_standardItemModel);默认行头和列头是存在的,如果要隐藏的话可以执行下面的代码:
tableView->horizontalHeader()->hide();
tableView->verticalHeader()->hide();
//方式二
tableView->verticalHeader()->setVisible(false);tableview视图如下:

2——tableview的单击元素的触发信号
connect(tableview, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableClicked(const QModelIndex &)));
void LTableView::onTableClicked(const QModelIndex &index)
{
qDebug() << "123";
if (index.isValid())
{
QString cellText = index.data().toString();
qDebug() << cellText;
}
}

3——tableview清除表格全部数据的方法
//方式1
m_standardItemModel->clear();
//方式2
m_standardItemModel->removeRows(0,m_standardItemModel->rowCount()); //删除所有行4——设置所有的列宽和行高
tableView->verticalHeader()->setDefaultSectionSize(32);
tableView->horizontalHeader()->setDefaultSectionSize(48);5——隐藏滚动条
//隐藏滚动条
m_ltableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);边栏推荐
- FileTool
- Baidu Post Bar crawler crawls to the middle of the building
- Qualcomm platform msm8953 display subsystem learning
- How to improve Baidu's weight
- (7)双向链表
- 【Oracle 数据库】奶妈式教程 day13 日期函数
- What are uniapp, wap2app and 5 + app in dccloud?
- Concurrent programming summary
- 模电实验——实验二 JFET共源极放大电路
- Simplicity is the best method of network promotion
猜你喜欢

IP address planning

目标检测系列——开山之作RCNN原理详解

Maptalks: basic operation and wms/wmts map service loading

SQL server changes the primary key index to a non clustered index

Vue page caching problem solving (keep alive + page level routing guard + lifecycle activated)

由浅入深拿下OpenFeign

(7)双向链表

OSI and tcp/ip

Xmind 2022思维导图激活版资源?

模電實驗——實驗二 JFET共源極放大電路
随机推荐
MySQL 8.0 under Linux forgets the password
数据可视化优秀案例
【Oracle 数据库】奶妈式教程 day12 字符函数
navicat如何查询已连接的数据库密码信息
itertools 排列组合
Node red sends wechat official account message (template message)
Wechat applets will directly open the parent element when the child element of flex:1 is too long (the text is too long)
MySQL query database capacity
SQL server changes the primary key index to a non clustered index
Remote Desktop Manager
【Oracle 数据库】奶妈式教程 day11 数值函数
Fmdb usage details mark
Difference between ID instancetype nsobject *
XMIND 2022 mind map active resources?
Applet vant UI implementation calls interface data and displays it
Asynchronous sending and receiving of message passing based concurrent programming (MPI)
【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构
Itemtools permutation
【 Oracle database】 Nursery Mother Tutorial day13 date Function
目标检测系列——开山之作RCNN原理详解