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

相关推荐
剩下了什么16 小时前
float32 与 float64 精度陷阱:如何在 Go 中避免错误使用
开发语言·后端·golang
指尖时光.16 小时前
Three.js 超全入门综合案例
开发语言·javascript·ecmascript
暴力求解16 小时前
Linux网络---传输层协议TCP(二)
linux·服务器·开发语言·网络·tcp/ip
吴声子夜歌16 小时前
Java面试题——基础(一)
java·开发语言
小庞在加油17 小时前
WinDbg实战:QT/跨平台项目死锁与无响应问题排查指南
开发语言·qt·windbg·工具
Vae_Mars17 小时前
C#中的delegate委托
开发语言·c#
一直走下去-明18 小时前
简单的http抓包解包完整代码
开发语言·python
caimouse18 小时前
ReactOS 图形系统分析(51):元文件子系统 — metafile.c
c语言·开发语言
hy.z_77719 小时前
【QT】1.QT初识(背景介绍、搭建开发环境、Qt Creator、程序、项目文件解析、编程注意事项)
qt
学习星球19 小时前
Solid.js 实战:拆解官方 RealWorld 项目
开发语言·javascript·vue.js