qt QTableview 左侧 序号 倒序

本文主要在QTableview插入数据的基础上,使左边序号实现倒序,实现如下图所示。

解决办法:

QTableview左侧是QHeaderView类构成的, 重写QHeaderView的paintSection, 重写序号的文字内容,进而****实现QTableview 左侧序号倒序

定义新类,并调用

复制代码
//.h 
class RealTimeTableHeaderView : public QHeaderView
{
public:
      NewHeaderView(Qt::Orientation orientation,
            QWidget * parent = nullptr) :
            QHeaderView(orientation, parent)
        {
            ;
        }

protected:
    void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const  override;
};


//.cpp

 void NewHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
 {
     QHeaderView::paintSection(painter, rect, count() - logicalIndex - 1);
 }

调用:

复制代码
    NewHeaderView *m_pNewHeaderView = nullptr;
    m_pNewHeaderView = new NewHeaderView(Qt::Vertical, ui->show_realtime_tableView);
    ui->tableView->setVerticalHeader(m_pNewHeaderView);

主要是:

QHeaderView::paintSection(painter, rect, count() - logicalIndex - 1);// 代表倒序

QHeaderView::paintSection(painter, rect, logicalIndex );// 代表正序

相关推荐
车端域控测试工程师2 分钟前
Autosar网络管理测试用例 - TC003
c语言·开发语言·学习·汽车·测试用例·capl·canoe
共享家95274 分钟前
特殊类的设计
开发语言·c++
雲烟11 分钟前
Qt SQLite在I.mx8上使用问题
数据库·qt·i.mx8
嘟嘟w33 分钟前
JVM(Java 虚拟机):核心原理、内存模型与调优实践
java·开发语言·jvm
信奥卷王1 小时前
2025年9月GESPC++三级真题解析(含视频)
开发语言·c++·算法
喵了几个咪1 小时前
Golang微服务框架kratos实现Socket.IO服务
开发语言·微服务·golang
q***42051 小时前
PHP使用Redis实战实录2:Redis扩展方法和PHP连接Redis的多种方案
开发语言·redis·php
qq_433554542 小时前
C++ 稀疏表
开发语言·c++·算法
z***y8622 小时前
Java数据挖掘开发
java·开发语言·数据挖掘
软件开发技术深度爱好者3 小时前
Python库/包/模块管理工具
开发语言·python