PDA

View Full Version : QGraphicsView Frame Rate



benlau
30th March 2010, 10:58
Hi ,

Anybody know what is the current frame rate of QGraphicsView? And is it possible to adjust manually?

Thanks for any advise.

pherthyl
30th March 2010, 19:15
QGraphicsView does not have a frame rate.
Are you talking about animations? In that case, it depends on how you're doing the animation and you need to provide more details.

benlau
31st March 2010, 10:57
yes , I mean animation.

I am trying to make an animation that move a list of pixmap from left to right. I didn't use State machine. I just make a list of QPropertyAnimation and set the start and end value.

However, the animation is a little bit choppy when it is run in full screen mode. Seem that it is out-sync-ed with screen refresh rate. Therefore I would like to adjust the frame rate / animation update rate.

wysota
31st March 2010, 11:08
If it's choppy then it means GraphicsView can't deal with that much information to process. You need to optimize some things by different ways described all over this forum (and not only here).

benlau
31st March 2010, 17:34
Thanks. But I find that even I move a single rectangle on QGraphicsView, it is slightly choppy... Anyway , I will check the old post first.

benlau
31st March 2010, 18:14
If I understand correctly (correct me if I am wrong) , in order to assign a specific update rate to view , it should :

1) Set QGraphicsView update module to NoViewportUpdate
2) Connect a timer's timeout signal to QGraphicsScene::update() slot

However, I have a question about the above behaviour. I think QGraphicsScene::update() would update every items on scene , no matter the region/rect is changed or not. Am I correct? Is it possible to update only the changed region/rect like what BoundingRectViewportUpdate mode do?

pherthyl
31st March 2010, 18:15
It shouldn't normally be choppy. However, many things can affect painting speed. If you're on linux you might want to enable the raster or opengl paint systems for more speed. If this is on windows you are almost certainly doing something wrong, since it should be plenty fast enough. Post more code for more help.

wysota
31st March 2010, 20:00
If I understand correctly (correct me if I am wrong) , in order to assign a specific update rate to view , it should :

1) Set QGraphicsView update module to NoViewportUpdate
2) Connect a timer's timeout signal to QGraphicsScene::update() slot
Not if you are using the Animation Framework. The framework runs its own timer. You can check the exact frequency in the sources but I wouldn't be surprised if it was dynamically calculated.

benlau
7th April 2010, 11:01
It shouldn't normally be choppy. However, many things can affect painting speed. If you're on linux you might want to enable the raster or opengl paint systems for more speed. If this is on windows you are almost certainly doing something wrong, since it should be plenty fast enough. Post more code for more help.

Thanks.

hmm... I think I should call it flickering instead of choppy. I made a very simple program with only a big red rectangle moving around the screen. With the options of -graphicssystem raster / opengl. It will look better. But still have a slightly fickering or tearing depend on system.

Linux:
- raster : flickering
- opengl: segfault (seem to be driver issue. )

Mac:
- raster : flickering
- opengl : tearing


The code


#include <QtGui>

class Rect : public QObject , public QGraphicsRectItem {
Q_OBJECT

public:
Q_PROPERTY(QPointF pos WRITE setPos READ pos)

Rect(QGraphicsItem* item = 0) : QObject(),QGraphicsRectItem(item) {
}
};

int main(int argc , char **argv){
QApplication app(argc,argv);

QGraphicsView view;
view.setViewportUpdateMode(QGraphicsView::Bounding RectViewportUpdate);
view.setCacheMode(QGraphicsView::CacheBackground);
view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

QGraphicsScene scene;

view.setScene(&scene);
scene.setSceneRect(0,0,1280,1024);

Rect* rect = new Rect();
rect->setRect(0,0,500,500);
scene.addItem(rect);

QBrush brush(Qt::red);
rect->setBrush(brush);
rect->setCacheMode(QGraphicsItem::DeviceCoordinateCache) ;

QPropertyAnimation anim(rect,"pos");
int duration = 5000;

anim.setStartValue(QPointF(0,0));
anim.setKeyValueAt(0.25 , QPointF(500,0) );
anim.setKeyValueAt(0.5 , QPointF(500,500) );
anim.setKeyValueAt(0.75 , QPointF(0,500) );
anim.setEndValue(QPointF(0,0));
anim.setDuration(duration);
anim.setLoopCount(-1);

anim.start();

view.show();


return app.exec();
}

#include "main.moc"

benlau
7th April 2010, 11:05
Not if you are using the Animation Framework. The framework runs its own timer. You can check the exact frequency in the sources but I wouldn't be surprised if it was dynamically calculated.

Thanks.

Becasue I may run the program on an embedded hardware, I am trying to avoid it did too much refresh that consume too much cpu power.

themk
12th October 2010, 18:32
Hi benlau,

I have the same problem, my code is very similar and same render hints,
have you resolved? how?

thank you

benlau
13th October 2010, 01:04
Hi themk,

I still can't find a prefect solution , the only way I could try is to avoid a big rectangle moving in a constant speed.

p.s I have patched Qt and allow it to set animation fps by environment variable.