Results 1 to 6 of 6

Thread: Issues with mapping with QTransform

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Issues with mapping with QTransform

    I have a set of points defines in world coordinates. I draw these points on to a pixmap and I have made use of a QTransform to map points from say... a scene rectangle of QRectF(1000,2000,4000,3000) to a pixmap of size (1000,1000). O.k. now I want to scale the points such that if the scene changes to QRectF(1000,2000,4000,1500) Instead of my points getting squeezed by half the height, I want the points to be scaled but also translated such that the 2 rectangles end up with the same center. In this way, if the height is half then the center point will be the same but the topLeft() and bottomRight() points will be adjusted.

    I have definitely looked at the code on QTransform and mapping. Matrices are not my strong point. Maybe I am missing a simple step.

    any help would be appreciated,

    spawn9997

  2. #2
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Thanks
    3
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with mapping with QTransform

    Is the pixmap a scene item too?

  3. #3
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Issues with mapping with QTransform

    Quote Originally Posted by pkohut View Post
    Is the pixmap a scene item too?
    The way it is setup, the QGraphicsItem displays the 'correct' pixmap depending on level of detail. Part of the function of 'MyGraphicsItem' is to initially draw itself onto a pixmap and then use the painter function QPainter::drawPixmap() in the QGraphicsItem::paint() function.

    Btw, using Qt 4.6.2.

  4. #4
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Thanks
    3
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with mapping with QTransform

    Can you calc the mid point of the source and then setPos on the pixmapItem?

    Totally not tested (or compiled), but looks correct
    Qt Code:
    1. QVector2d vTopLeft(rect.topLeft());
    2. QVector2d vMid = vTopLeft + ((QVector(rect.bottomRight()) - vTopLeft) * 0.5);
    3. pixmap->setPos(vMid->toPointF());
    To copy to clipboard, switch view to plain text mode 
    Last edited by pkohut; 4th January 2011 at 16:59.

  5. The following user says thank you to pkohut for this useful post:

    spawn9997 (5th January 2011)

  6. #5
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Issues with mapping with QTransform

    @pkohut I actually figured it out before I looked at this. I basically did exactly what you suggested. I forgot to set the new scaled Rectangle's center to the old Rectangle's center. The scaled rectangle is used to map points to the pixmap. I was mapping to a rectangle at the wrong position, Doh! When I called
    Qt Code:
    1. QRectF tmp(x,y,w,h);
    2. tmp.moveCenter(m_realRect.center());
    To copy to clipboard, switch view to plain text mode 
    and then mapped the points to this rectangle, everything looked exactly as it was supposed to.

  7. #6
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Thanks
    3
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with mapping with QTransform

    Quote Originally Posted by spawn9997 View Post
    Qt Code:
    1. QRectF tmp(x,y,w,h);
    2. tmp.moveCenter(m_realRect.center());
    To copy to clipboard, switch view to plain text mode 
    Ha, scanned right past center and moveCenter, was looking for middle.

Similar Threads

  1. QTransform()
    By mkind in forum Newbie
    Replies: 0
    Last Post: 19th February 2010, 21:45
  2. GraphicsItemChange and QTransform
    By ct-xuyaojun in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2009, 09:16
  3. QTransform + drawLine ?
    By verburg in forum Qt Programming
    Replies: 0
    Last Post: 23rd January 2009, 00:32
  4. Mouse mapping on QTransform problem
    By captchaq in forum Newbie
    Replies: 2
    Last Post: 26th September 2008, 19:11
  5. QTransform vs QMatrix
    By maverick_pol in forum Qt Programming
    Replies: 7
    Last Post: 4th October 2007, 10:53

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
  •  
Qt is a trademark of The Qt Company.