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 );// 代表正序

相关推荐
阿pin3 分钟前
Android随笔-View绘制流程
android·开发语言·view
敖行客 Allthinker28 分钟前
IM 融合专题:后端架构师的核心修炼
java·开发语言·数据库
进击的程序猿~33 分钟前
Go Slice源码深度解析指南
开发语言·后端·golang
Hesionberger36 分钟前
快速求解完全平方数的最少数量
开发语言·数据结构·python·算法·leetcode·c#
西门吹-禅11 小时前
java springboot N+1问题
java·开发语言·spring boot
skywalk816311 小时前
设计并实现段言的 C FFI 绑定机制 @Trae
c语言·开发语言·python·编程
IT笔记13 小时前
【Rust】Rust Match 模式匹配详解
java·开发语言·rust
2zcode13 小时前
免费开源项目文档:基于MATLAB卷积神经网络的口罩佩戴检测系统
开发语言·matlab·cnn
逝水无殇13 小时前
C# 运算符重载详解
开发语言·后端·c#
TPBoreas14 小时前
配置信息防泄露方案:.env 环境隔离详解(dotenv-java)
java·开发语言