Important: Please read the Qt Code of Conduct -

[SOLVED] QGraphicsView and scale

  • Graphics view has function scale(qreal,qreal) which scales objects inside it. How to get scale factor of my view ? I found that I cam get transformation matrix using transformation() function, but how can I get factor value using this or maybe other ideas ?

  • QTransform is returned by the QGraphicsView::transform(). Please take a look at QTransform class information, you can find there the description of basic matrix operations and this is what you are looking for.

  • I mean can I get scaleFactor from this transformation matrix and if yes - how ? I don't need to do any transform operations on this step, I just need to get current scale factor.

  • Yes, you can. The elements m11 and m22 in the matrix operations.

  • Sorry I found that it's m11 and m22. Thanks,dakron.

  • Please mark post as [SOLVED]

  • I know this topic is quite old, but I want to update the solution. I used the solution from dakron but got weird behavior sometimes.
    m11 for x and m22 for y works only if the view has no rotation applied. If the view is rotated the returned values will be wrong.
    You can calculate the x scale with 'sqrt(trf.m11() * trf.m11() + trf.m12() * trf.m12())' (pythagoras, where trf is the QTransform) and y with 'sqrt(trf.m21() * trf.m21() + trf.m22() * trf.m22())'.

Log in to reply