How to draw text in derived from QHeaderView class

2019-06-08 01:58发布

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");
}

1条回答
霸刀☆藐视天下
2楼-- · 2019-06-08 02:29

The documentation says:

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

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");
}
查看更多
登录 后发表回答