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

相关推荐
做怪小疯子19 分钟前
JavaScript 中Array 整理
开发语言·前端·javascript
旭编20 分钟前
牛客周赛 Round 117
java·开发语言
六元七角八分26 分钟前
CSDN文章如何转出为PDF文件保存
开发语言·javascript·pdf
froginwe1133 分钟前
MongoDB 删除数据库
开发语言
Java小混子34 分钟前
golang项目CRUD示例
开发语言·后端·golang
想搞艺术的程序员37 分钟前
Go 优雅关闭实践指南:从原理到框架落地
开发语言·后端·golang
m5655bj42 分钟前
Python 查找并高亮显示指定 Excel 数据
开发语言·python·excel
洛克希德马丁1 小时前
Qt 配置Webassemble环境
开发语言·qt·webassembly·emscripten·emsdk
武子康1 小时前
Java-167 Neo4j CQL 实战:CREATE/MATCH 与关系建模速通 案例实测
java·开发语言·数据库·python·sql·nosql·neo4j
自由的好好干活1 小时前
C#桌面框架与Qt对比及选型(国产操作系统开发视角)
开发语言·qt·c#