PDA

View Full Version : Qt4.1 Mouse Position & Scaling



Paul Drummond
16th February 2006, 19:21
Hi All,

I am making an application which draws lines and points on the screen where the user can select and drag the "points", much like the Qt "pathstroke" example.

Currently, I am trying to add the ability to zoom in and out which is quite simple from a visual perspective - I just add scaleFactor variable (set to 1.0 initially) then call QPainter::scale(m_scaleFactor, m_scaleFactor) in my paint event. No problems.

The problems comes when I zoom in then try to select a "point". Obviously, I need to convert the mouse position into the correct units, but no matter what I try to do, it doesn't work.

I assumed it was just a case of applying the scaleFactor to the mouse position but maybe I am being WAY TO naive here. Can anyone point me in the right direction? Can this be acheived simply or should I go away and read a book on vector graphics?

orb9
16th February 2006, 20:02
Can this be acheived simply or should I go away and read a book on vector graphics?

I think you don't need to read the book. Try.


QPoint p = somePoint;
QPoint transformedPoint = painter->matrix().map( p );

But theoretically applying the zoom factor should work too, as long as you don't use the translation and rotation part of the painter's transfrom matrix by calling translate(), rotate() or shear(). But i'm not a math expert, too - so maybe i'm wrong here.