【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);
    }
}
相关推荐
kaixin_learn_qt_ing10 小时前
Qt Model/View
qt
Quz11 小时前
QML MouseArea:鼠标拖拽与滚轮缩放
qt·qml
CHPCWWHSU12 小时前
DeepSeek-Harness-Qt将浏览器端Agent装入桌面应用
开发语言·qt
飘忽不定的bug17 小时前
ubuntu20.04交叉编译QT5.15.12(RK3562+ubuntu20.04)
linux·qt·ubuntu
秋田君19 小时前
Qt_QMediaPlayer类与QMediaPlaylist类
开发语言·qt
mengzhi啊19 小时前
QT程序界面自适应1080/2K/4K屏幕。qputenv或者setAttribute
qt
C++ 老炮儿的技术栈19 小时前
Qt5 使用 QPainter 绘制阿基米德螺线
开发语言·c++·windows·qt·代码化
大丑哥2 天前
QT QML 中实现高亮功能
qt
小白不想画工图2 天前
银河麒麟V10系统安装QT5.12
linux·开发语言·qt·银河麒麟
mengzhi啊2 天前
QEventLoop loop配合loop.exec();替代while(1)。电脑cpu占用为0,使用while(1)cpu占用率100%
c++·qt