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

相关推荐
我叫汪枫8 分钟前
【刷机分享】解决K20Pro刷入PixelOS后“网络连接”受限问题(附详细ADB命令)
开发语言·adb·php
老程序员刘飞8 分钟前
hardhat 搭建智能合约
开发语言·php·智能合约
Autism11421 分钟前
javase-day22-stream
java·开发语言·windows·笔记
江塘22 分钟前
机器学习-KNN算法实战及模型评估可视化(C++/Python实现)
开发语言·c++·人工智能·python·算法·机器学习
KL418024 分钟前
【QT】窗口
c++·qt
钟离墨笺35 分钟前
Go语言-->Goroutine 详细解释
开发语言·后端·golang
Dontla36 分钟前
JS睡眠函数(JS sleep()函数、JS单线程、Event Loop事件循环)假睡眠
开发语言·javascript·ecmascript
李游Leo43 分钟前
Rokid UXR3.0 手势算法与接入实践(v3.0.3)—设备适配、能力边界与示例代码
开发语言
艾莉丝努力练剑1 小时前
【C++:继承和多态】多态加餐:面试常考——多态的常见问题11问
开发语言·c++·人工智能·面试·继承·c++进阶
Skrrapper1 小时前
【C++】C++11出来之后,到目前为止官方都做了些什么更新?
开发语言·c++