QGraphicsView或QWidget完成绘制或渲染时是否存在信号或事件? [英] Does a signal or event exist for when a QGraphicsView or QWidget is done being painted or rendered?

查看:111
本文介绍了QGraphicsView或QWidget完成绘制或渲染时是否存在信号或事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试给应用程序计时,以查看加载一些信息和绘制图形所花费的时间.我的函数首先加载数据,然后绘制图形.

I'm trying to time an application to see how long it takes to load up some information, and paint a graph. My function loads up the data first, then draws the graph.

计时非常简单,它调用一个自某个日期起获得毫秒数的外部函数.问题是,即使我在调用draw函数之后将t1设置为开始,并将t2设置为立即,在实际更新QGraphicsView之前,t2也会返回.(我知道,为什么这应该是异步的)

The timing is fairly simple, it calls an external function that gets msecs since some date. The problem is even if I set t1 in the beginning and t2 right after I call the draw function, t2 will return before the QGraphicsView is actually updated. (I know, it makes sense why this should be asynchronous)

例如,当我加载一个大文件时,在减去两个值后它将以700毫秒的速度返回,但是直到几秒钟后,实际渲染才会完成.

For instance when I load a large file, it will return with 700 msecs after I subtract the two values, but the actual rendering doesn't finish until a few seconds later.

我在网上浏览了所有内容,并仔细研究了Qt文档.我可以找到大量有关自己更新小部件的信息,但是在渲染完成后不会触发的任何信号或事件上却找不到任何信息.

I've looked all over the web and scoured the Qt documentation. I can find tons of information on updating widgets yourself, but nothing on any kind of signal or event that is fired off after rendering finishes.

即使 QGraphicsScene :: changed 信号似乎也仅在下面的场景发生更改时才触发,而不是在渲染完成后触发,用户可以看到更改.

Even the QGraphicsScene::changed signal appears to only be fired off when the scene changes underneath, not when rendering is done and the user can SEE the changes.

有关如何执行此操作的任何帮助?

Any help on how to do this?

推荐答案

我没有进行测试,但是我认为通过将 QGraphicsScene 子类化并重新实现 render 方法,您可以测量渲染时间.

I have not testet it, but I think by subclassing QGraphicsScene and reimplementing the render method you can measure the render time.

#include <QGraphicsScene>
#include <QTime>

class MyGraphicsScene : public QGraphicsScene 
{
Q_OBJECT
public:
void render ( QPainter * painter, const QRectF & target = QRectF(), const QRectF & source = QRectF(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio ) {
   QTime t;
   t.start();
   QGraphicsScene::render (painter, target, source, aspectRatioMode);
   qDebug("render time %d msec", t.elapsed());
}
};

这篇关于QGraphicsView或QWidget完成绘制或渲染时是否存在信号或事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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