当前位置: 首页 > news >正文

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

http://www.lryc.cn/news/462004.html

相关文章:

  • 隧道代理IP如何帮助企业采集数据?
  • Spring Boot知识管理系统:技术与方法论
  • SpringBoot1~~~
  • 兼容多家品牌手机的多协议取电快充芯片
  • Java和Python的不同
  • Moshang摩熵医药数据库
  • 基于web的酒店客房管理系统【附源码】
  • 潜水定位通信系统的功能和使用方法_鼎跃安全
  • Golang | Leetcode Golang题解之第477题汉明距离总和
  • JavaWeb——Maven(1/8):整体介绍(什么是Maven、Maven的作用、小结)
  • Vivado 跟Xilinx SAE学HLS系列-高亚军(复合数据类型)
  • 【mysql】WITH AS 语法详解
  • Rocky linux SSD安装
  • 在 Linux 系统中设置 Service 服务开机自启的详细指南
  • Flythings学习(四)串口通信
  • [数据结构]带头双向循环链表的实现与应用
  • 商品详情数据API接口开发系列(属性规格详情图sku等)
  • 在 Ubuntu 上安装 clang-format-14
  • 【优选算法篇】双指针的华丽探戈:深入C++算法殿堂的优雅追寻
  • 【springboot入门-mvc常用注解使用方式及原理】
  • 滚雪球学Redis[4.2讲]:Redis Sentinel 深度解析:工作原理、配置与高可用架构下的故障转移
  • Vue3 -- 设置分页,切换分页之后选项仍能保留 控制多个表格的选中不会互相影响
  • 如何在 JSON 中编写“anyOf”语句?
  • python开发环境配置
  • QT开发--QT SQL模块
  • 如何保证接口幂等性?
  • 【9718】基于springboot+vue的生鲜交易系统
  • Spring循环依赖解决方案
  • 解决 IntelliJ IDEA 运行时 “Command line is too long“ 问题
  • 鸿蒙网络编程系列5-TCP连接超时分析