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

相关推荐
沐知全栈开发1 天前
HTML5 浏览器支持
开发语言
wasp5201 天前
AgentScope Java 核心架构深度解析
java·开发语言·人工智能·架构·agentscope
WHOVENLY1 天前
【javaScript】- 笔试题合集(长期更新,建议收藏,目前已更新至31题)
开发语言·前端·javascript
慌糖1 天前
流-为序列化解释
开发语言
LXS_3571 天前
Day 18 C++提高 之 STL常用容器(string、vector、deque)
开发语言·c++·笔记·学习方法·改行学it
王琦03181 天前
Python 函数详解
开发语言·python
胡伯来了1 天前
13. Python打包工具- setuptools
开发语言·python
小鸡吃米…1 天前
Python 中的多层继承
开发语言·python
deng-c-f1 天前
Linux C/C++ 学习日记(53):原子操作(二):实现shared_ptr
开发语言·c++·学习
wanghowie1 天前
01.07 Java基础篇|函数式编程与语言新特性总览
java·开发语言·面试