Results 1 to 2 of 2

Thread: Qt4.1 Mouse Position & Scaling

  1. #1
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Qt4.1 Mouse Position & Scaling

    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?

  2. #2
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4.1 Mouse Position & Scaling

    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.
    Qt Code:
    1. QPoint p = somePoint;
    2. QPoint transformedPoint = painter->matrix().map( p );
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 05:56
  2. Mouse position on screen
    By Nippler in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 15:22
  3. grabbing position of mouse
    By safknw in forum Qt Programming
    Replies: 10
    Last Post: 28th June 2008, 16:00
  4. Enter event mouse position
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 7th May 2008, 19:53
  5. Clearing a QLabel since the mouse position
    By SkripT in forum Qt Programming
    Replies: 10
    Last Post: 18th January 2006, 19:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.