gpt4 book ai didi

c++ - 未调用 QGraphicsItem 绘画

转载 作者:行者123 更新时间:2023-11-30 02:55:23 26 4
gpt4 key购买 nike

我使用QGraphicsViewQGraphicsSceneQGraphicsItem 来绘制一些图表。我已经实现了用于绘制文本(图表的值)的 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 不能被调用,我怎样才能让它被调用?

最佳答案

您需要从修改 m_value 变量的函数中调用 QGraphicsItem::update() 以触发重绘。

关于c++ - 未调用 QGraphicsItem 绘画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16497497/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com