protected:
virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->drawRect(2, 2, 10, 10);
}矩形不是绘画。但当paintSection移除它时,它就是绘画。我需要在调用基础paintSection之后绘制矩形。
发布于 2014-08-26 17:12:26
正如你的问题在this中回答的那样,rect是你应该画的一个区域。
如果您在此区域之外进行绘制,您的绘图可能会因为绘制其他单元格而被擦除。
所以使用rect来绘制一个矩形:
painter->drawRect(rect.adjusted(2, 2, -2 , -2));发布于 2019-07-31 03:19:57
你需要在调用super的过程中保护绘制器,这会修改它。试试这个:
painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();此外,正如Ezee所指出的,您应该使用传入的rect作为绘制坐标的基础;正如在该答案中所建议的,类似于:
painter->drawRect(rect.adjusted(2, 2, -2 , -2));https://stackoverflow.com/questions/25489640
复制相似问题