为QHeaderView交付的类实现paintSection [英] Implement paintSection for QHeaderView delivered class

查看:521
本文介绍了为QHeaderView交付的类实现paintSection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected:
  virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
  {
    QHeaderView::paintSection(painter, rect, logicalIndex);
    painter->drawRect(2, 2, 10, 10);
  }

矩形未绘制.但是,当paintSection删除时,它就是绘画.我需要在调用base paintSection之后绘制矩形.

Rectangle is not painting. But when paintSection removed it is painting. I need to draw rectangle after call base paintSection.

推荐答案

您需要在对super的调用(它对其进行修改)中保护画家.试试这个:

You need to protect the painter across the call to super, which modifies it. Try this:

painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();

此外,正如Ezee所指出的那样,您应该使用传入的rect作为绘制坐标的基础;如该答案中所建议的,类似:

Also, as Ezee noted, you should be using the rect passed in as the basis for the coordinates you draw at; as suggested in that answer, something like:

painter->drawRect(rect.adjusted(2, 2, -2 , -2));

这篇关于为QHeaderView交付的类实现paintSection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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