如何在从QHeaderView类派生的文本中绘制文本 [英] How to draw text in derived from QHeaderView class

查看:104
本文介绍了如何在从QHeaderView类派生的文本中绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从QHeaderView类派生文字.但是此代码不起作用.

I need to draw text in derived from QHeaderView class. But this code does not work.

void HeaderView::paintSection(QPainter *painter, const QRect &, int) const
{
    painter->drawText(0, 0, "abcde");
}

推荐答案

文档说:

使用 给画家和直肠.

Paints the section specified by the given logicalIndex, using the given painter and rect.

这意味着,您必须使用rect Getting作为参数:

That means, you have to use the rect getting as parameter:

void HeaderView::paintSection(QPainter *painter, const QRect& rect, int) const
{
    painter->drawText(rect, Qt::AlignCenter, "abcde");
}

这篇关于如何在从QHeaderView类派生的文本中绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆