我使用QGraphicsView,QGrapichsScene和QGraphicsItem来绘制一些图表。我已经实现了绘制文本(图表的值)的QGraphicsItem::paint函数,但它并不是每次都被调用,这是必须绘制新的东西。我的paint函数
void CLabelItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget = 0*/)
{
if ( GetValue() < 0 )
{
return;
}
painter->drawText(boundingRect(), m_value.toString());
}所以我的问题是-为什么QGraphicsItem::paint不能被调用,以及如何让它被调用?
发布于 2013-05-12 00:22:17
您需要从修改m_value变量的函数中调用QGraphicsItem::update()来触发重新绘制。
发布于 2013-05-11 22:34:36
通常,在Qt中,当调用paintEvent时绘制图形项,然后您可以在paint函数中处理绘制。
https://stackoverflow.com/questions/16497497
复制相似问题