Use particles in QGraphicsScene



  • Hi all

    From what I know Qt particle system used in QtQuick is not available from C++ side (correct? It will be available in the future?). Now, excluding to make some hack in Qt libraries source for "export" QML particle engine, is there another way to have particle usable from QGraphicsScene? I guess a possible solution would be to implement particle by hand but in this case particle explosion, for example, it will be the result of hundreds of QGraphicsItem objects moved by the Qt animation engine like QAnimationProperty and QParallelAnimation? Sorry for the question can be stupid but I'm not expert in how particle are managed...
    Thank you



  • @Suppaman The QML particle engine is implemented using scene graph APIs, so even if it was made available through C++, there is no way to use it in combination with a QGraphicsScene.

    To implement particles manually in graphics view, you need to implement it as a single particlesystem item. Using a unique item per particle and animation objects to control each of those will be far to heavy unless you want to limit yourself to 100 particles.

    Instead, use a custom item with a paint() function that makes use of the QPainter::drawPixmapFragments() function. That allows you to create an array with an entry for each particle which can be drawn in a single QPainter call. If your graphics view is running on an OpenGL viewport, that translates to a single glDrawXxx call which will give you very good performance.

    Another option for a large amount of particles would be do native GL with the use of QPainter::beginNativePainting()/endNativePainting(), again assuming that your graphics view is rendering to a GL viewport.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.