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

相关推荐
傻乐u兔1 分钟前
C语音初阶————调试实用技巧2
c语言·开发语言
沛沛老爹9 分钟前
从Web到AI:行业专属Agent Skills生态系统技术演进实战
java·开发语言·前端·vue.js·人工智能·rag·企业转型
程农31 分钟前
基于Java的报名系统
java·开发语言
yugi9878381 小时前
基于字典缩放的属性散射中心参数提取MATLAB仿真程序
开发语言·matlab
小白学大数据2 小时前
绕过拼多多 App 反抓包机制的综合逆向解决方案
开发语言·爬虫·python·自动化
使者大牙2 小时前
【单点知识】 Python装饰器介绍
开发语言·数据库·python
带土12 小时前
2. C++ private、protected、public
开发语言·c++
我不是8神2 小时前
字节跳动 Eino 框架(Golang+AI)知识点全面总结
开发语言·人工智能·golang
古城小栈2 小时前
Rust复合类型 四大军阀:数、元、切、串
开发语言·后端·rust
kong79069282 小时前
Python核心语法-Python自定义模块、Python包
开发语言·python·python核心语法