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

相关推荐
xieliyu.5 小时前
Java算法精讲:双指针(二)
java·开发语言·算法
爱思考的小伙5 小时前
Qt-03:串口助手
qt
何以解忧,唯有..5 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
雪的季节6 小时前
RabbitMQ详解
开发语言
ice8130331816 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
三品吉他手会点灯6 小时前
C语言学习笔记 - 44.运算符和表达式 - 运算符2 - 除法与取余运算符
c语言·开发语言·笔记·算法
kkeeper~6 小时前
0基础C语言积跬步之动态内存管理
c语言·开发语言
橘右今7 小时前
2026 Java后端高频面试宝典
java·开发语言·面试
微小冷7 小时前
Julia卫星工具箱SatelliteToolbox简介
开发语言·航天·坐标转换·julia·卫星工具箱
2601_colin7 小时前
Codex插件全流程实战指南
开发语言·经验分享·笔记·微信开放平台