Important: Please read the Qt Code of Conduct -

item translation with QTransform vs change item position

  • Hi all,

    I have a big QGraphicsPixmapItem in my QGraphicsView, so I have implemented some scene movement. I mean when I drag mouse - pixmap is moved so I can see different parts of the picute. I can do this two ways:

    1. by applying QTransform to the QGraphicsItem with translation set in the matrix
    2. by changing QGraphicsItem x,y position with .setPos() function.

    Is there some difference between these two mechanizm especially with performance?
    In fact I did this with QTransform, but would like to switch to simply setPos with the item if the performance of the app will not be affected.
    Maybe these two mechanizm uses the same method behind the scenes ?

    Best Regards

  • Moderators

    I'd use the simplest solution, i.e. QGraphicsItem::setPos(). QTransform resorts to a matrix to perform complex transformations in a single step so using it only for translation seems like overkill (performance shouldn't much suffer though).

    Is there some difference between these two mechanizm especially with performance?

    I don't know for sure.

  • @kshegunov
    QGraphicsItem::setPos() is what I'm asking about.
    I have used QTransoform because except for translation I'm also scaling the picture, but probably you are right, I should try.

    Best Regards

  • Lifetime Qt Champion


    Both are different concepts. setPos simply sets the position of the item within the scene. When you call setTransform, you modify the object from where it can be found.

    As for performances, you should benchmark both options.

  • I was testing on my Linux box and I got impression that with setPos picture sometimes flicker, but app should work on Tablet and Phones where CPU is less powerful . So I guess I need to checki it, QTransform works fine on mobile devices.

Log in to reply