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

相关推荐
IMPYLH几秒前
Lua 的 select 函数
java·开发语言·笔记·后端·junit·游戏引擎·lua
JienDa5 分钟前
JienDa聊PHP:知乎仿站实战中PHP框架的协同架构方略
开发语言·架构·php
hashiqimiya6 分钟前
android将json数据传递到后端springboot
java·开发语言
lijiatu100866 分钟前
[C++] 上锁、解锁、获取锁、释放锁的区别
开发语言·c++
D***t13110 分钟前
Swift在iOS中的多任务处理
开发语言·ios·swift
mit6.82412 分钟前
C 语言仓库引入 Rust: MCUboot 为例
开发语言·rust
阿沁QWQ13 分钟前
STL和string实现
开发语言·c++
f***686014 分钟前
MS SQL Server partition by 函数实战二 编排考场人员
java·服务器·开发语言
vi1212319 分钟前
ENVI 地形量化与植被指数反演
开发语言·python
u***284722 分钟前
golang debug调试
开发语言·后端·golang