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

相关推荐
RAN114267600824 分钟前
1.3第一个程序的介绍
开发语言·qt
blue_ice .1 小时前
Verilog DDS 数字信号发生器:DAC 输出模拟波形与 ADC 回采观测
开发语言·单片机·嵌入式硬件·fpga开发
远翔调光芯片^138287988721 小时前
ECP5702能芯科技PD取电芯片在市场上的优势有哪些?
开发语言·人工智能·单片机·嵌入式硬件·智能家居
泡海椒2 小时前
规则引擎对比:JQuick-Java vs Drools 轻量场景选型对比
java·开发语言
泡泡鱼(敲代码中)3 小时前
Python 容器类型学习笔记:列表、元组、字典、集合
开发语言·笔记·python·pycharm
2501_933670793 小时前
平台招商运营校招能力模型:数据分析、SQL与增长场景拆解
开发语言
菜鸟~noob2333 小时前
【Bonjour】华为Peerium架构深度解析:从冯·诺依曼到百万处理器“一台计算机”,附MATLAB性能仿真【含matlab代码,可直接运行】
开发语言·matlab·华为·peerium
白远山4 小时前
24小时自助健身房系统开发实战:从需求分析到完整指南
java·开发语言·数据库·数据挖掘·需求分析
shmily麻瓜小菜鸡6 小时前
TDD(测试驱动开发)详解
开发语言·javascript·typescript·node.js·ecmascript
三克的油6 小时前
java-学习1
java·开发语言·学习