【问题标题】:Qt: Force QGraphicsItem to updateQt:强制 QGraphicsItem 更新
【发布时间】:2013-11-22 17:50:57
【问题描述】:

根据Qt Documentation“void QGraphicsItem::update (const QRectF & rect = QRectF())”不会导致立即绘制;相反,它会在控制到达事件循环后安排由 QGraphicsView 处理的绘制请求。 这是我的代码:

this->item->setPixmap( QPixmap::fromImage(*coloration->image) );// QGraphicsPixmapItem 
this->item->update();
this->scene->update(); // QGraphicsScene
this->view->update(); // QGraphicsView

并且代码在一个每 100 毫秒调用一次的方法中(并且其中 coloration->image 会改变),但是 Qt 拒绝每 100 毫秒更新一次图像,它只渲染最终图像。那么,我怎样才能立即绘制该项目

【问题讨论】:

  • 你试过Animation Framework吗?
  • @graphite 实际上,我的项目不会产生动画,它只是对图像进行一些处理然后更新图像,所以我认为动画不是一个合适的选择。您知道如何使用 QGraphicsItem 处理问题吗?
  • 在处理图像时是否将控制权交给事件循环?
  • @graphite 感谢您的回复!我发现重新绘制视口就可以了!所以在方法中,只要调用 this->item->setPixmap( QPixmap::fromImage(*coloration->image) ); this->view->viewport()->repaint();
  • @JavaBeta 非常感谢您花了这么多时间。它是视口。我认为您应该将其写为答案。并为读者自己接受。

标签: qt qgraphicsitem


【解决方案1】:

您必须阻止您的事件循环,否则您对该项目的实施是不好的。我无法重现您的问题。

【讨论】:

    【解决方案2】:

    这对我有用: ui->graphicsView->viewport()->repaint();

    【讨论】:

      【解决方案3】:

      添加额外的用法

      #include <QGraphicsView> 
      QGraphicsView *view = scene()->views().first();
      view->viewport()->repaint();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多