PDA

View Full Version : QML or QGraphicsView?



been_1990
27th October 2010, 00:11
I'm going to develop a game that relies heavily on animation, hit-testing, state changing, creating/moving/destroying many objects.
Two/four/six/eight views with the same scene and tile based map.
So, should I use QML or QGraphicsView?

wysota
27th October 2010, 00:25
Well... strictly speaking QML (or rather QtQuick) is also QGraphicsView so you'll be using Graphics View anyway. If you want multiple views on one scene then as far as I remember you can't use Qt Quick, it's a one-to-one (or one-to-zero) relation only.

been_1990
27th October 2010, 02:20
Why does it seem that QML is faster? When I use the Qt Demo QML apps, they work very smooth. But when I use graphics view, updating items positions is so slow...
I think using setPos() might be the culprit. Should I subclass QGraphicsSvgItem and use it's paint() to update it's position?
I saw this example (http://doc.trolltech.com/4.3/tutorial-t11.html) and they subclass a QWidget, reimplement paintEvent() and paint an updated QRect to reflect the items position. Would that help with the speed of QGraphicsView?

aamer4yu
27th October 2010, 07:15
I guess with QML comes more of javascript...
Most examples I have seen use javascript for function implementation.

While coding in graphicsview, you will be directly using Qt classes. QML also finally converts the code to Qt graphicsview code.

wysota
27th October 2010, 10:30
Why does it seem that QML is faster?
Because QtQuick is fine tuned to some specific use cases.

But when I use graphics view, updating items positions is so slow...
Because your code is not optimal.


I think using setPos() might be the culprit. Should I subclass QGraphicsSvgItem and use it's paint() to update it's position?
No, definitely not. That would break the whole architecture.

been_1990
27th October 2010, 13:13
Because your code is not optimal.

What would make my code optimal? The code I use gets the mouse position increment(from raw input), then sets the item with setPos():


QGraphicsSvgItem * redPointer = new QGraphicsSvgItem(QCoreApplication::applicationDirP ath().append("/redPointer.svg"));

void Widget::mouseCoord(int x, int y){
redPointer->setPos(QPointF::QPointF(redPointer->x()+x/3, redPointer->y()+y/3));
}

But that gets awfully slow , any pointers on how to optimize?

wysota
27th October 2010, 13:18
What would make my code optimal?
Fixing the slowest parts of it. What the slowest parts are depends on the use case.


The code I use gets the mouse position increment(from raw input), then sets the item with setPos():
setPos() is not the bottleneck.


But that gets awfully slow , any pointers on how to optimize?
I'd start by enabling the item cache.

steno
27th October 2010, 18:58
I would also check QGraphicsScene and see what you have set on your ItemIdexMethod. If your scene is highly dynamic and you have BspTreeIndex enabled, it could cause a slow down there.