How to draw text in derived from QHeaderView class

为君一笑 提交于 2019-12-08 04:02:18

问题


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:


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


来源:https://stackoverflow.com/questions/25500085/how-to-draw-text-in-derived-from-qheaderview-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!