QPainter performance



  • Hi, I am trying to improve my programs performance. almost 50% of the time is using QPainter stuff on a QImage, and the doing some rasterization algorithms.
    that is:

    1. painting some QPainterPath and circles.
    2. reading the pixels and compering them.

    please advise regarding improving QPainters performance.


  • Moderators

    @yoavmil Sounds like you are doing some fairly intense stuff. Without seeing your code to find out why you are taxing QPainter so much it's hard to guess what is going on.

    My advice is to maybe switch to QGraphicsScene/View. That is made for graphics rendering and should be 1000x faster than a normal widget paint.

    But again I have no idea what you are doing or trying to do from the vague description so that is the best I can offer right now.


  • Qt Champions 2016

    I agree with @ambershark, you need to provide more information on what you're doing. However as a very general suggestion, you can try threading the operations onto the image. It sounds a bit iffy, but should work as long as you don't have overlapping regions worked by different threads.



  • @ambershark said in QPainter performance:

    That is made for graphics rendering and should be 1000x faster than a normal widget paint.

    That's not true. One rendering of complete scene from scratch with QPainter on one widget will not be slower than doing the same with QGraphicsScene, in fact it can be done substantially faster if painting is optimized. I guess this is the case that @yoavmil is talking about, drawing static scene once to QImage.

    Things change drastically if scene is not static, in this case QPainter may be come less efficient if you cannot limit repaints to tiny regions, and if OpenGL is used QGraphicsView can get better advantage of items that don't change by caching them and just recompositing. That said, there is no clear winner here as well, and profiling needs to be done for each particular case, though use of QGraphicsScene may result in simpler code.

    "1000x" thing may only be relevant for building scenes out of very many QWidgets. In this case QGraphicsView/QGraphicsScene may be orders of magnitude more efficient.


  • Moderators

    @Konstantin-Tokarev said in QPainter performance:

    "1000x" thing may only be relevant for building scenes out of very many QWidgets. In this case QGraphicsView/QGraphicsScene may be orders of magnitude more efficient.

    Yea I did make that assumption that he was building a complex scene since I have never had a performance issue with QPainter before, even in mildly complex scenes. Also 1000x was definitely hyperbole as it wouldn't realistically be anywhere near that. ;)


Log in to reply
 

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