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

相关推荐
huohuopro几秒前
Mybatis的七种传参方式
java·开发语言·mybatis
Lee_SmallNorth2 分钟前
变态需求之【角色不同访问数据库的用户不同】
java·开发语言·数据库
扶苏-su4 分钟前
Java网络编程:InetAddress 详解
java·开发语言·网络
IOT-Power1 小时前
QT构建构建DataBus总线
开发语言·qt
Ophelia(秃头版1 小时前
JS事件循环与NodeJS事件循环(libuv)
开发语言·javascript
米饭的白色1 小时前
matlab 中 `对数坐标` 画图下的 `hold on` 位置对坐标轴刻度的影响
开发语言·matlab
gjxDaniel1 小时前
Go编程语言入门与常见问题
开发语言·后端·go
建群新人小猿2 小时前
陀螺匠企业助手——组织框架图
android·java·大数据·开发语言·容器
CV_J2 小时前
索引库操作
java·开发语言·elasticsearch·spring cloud
阿蒙Amon2 小时前
C#每日面试题-简述异常处理
开发语言·c#