【Qt】QItemSelectionModel 添加选中行

1. 介绍

QItemSelectionModel 中没有直接添加选中行的方法,可以通过下面的方式添加。

2. 代码

c 复制代码
//定义
QSqlTableModel* m_tableModel;
QItemSelectionModel* m_selectionModel;

//添加选中行, 全选
void addAllLine()
{
	for(int i=0; i<m_tableModel->rowCount(); i++)
    {
        QModelIndex startIdx = m_tableModel->index(i, 0);
        QModelIndex endIdx = m_tableModel->index(i, m_tableModel->columnCount()-1);
        
        QItemSelection selection = QItemSelection(startIdx, endIdx);
        m_selectionModel->select(selection, QItemSelectionModel::Select);
    }
}
相关推荐
用户805533698034 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner5 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz10 天前
QML Hello World 入门示例
qt
xcyxiner13 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner13 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner13 天前
DicomViewer (添加模型类)3
qt
xcyxiner14 天前
DicomViewer (目录调整) 2
qt
xcyxiner14 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能16 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G16 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt