Results 1 to 2 of 2

Thread: Zooming does not work after QTransform

  1. #1

    Default Zooming does not work after QTransform

    Hi,

    I'm trying to implement a function to transform polygons, using QTransform. It works, but it's only transforming around the top-left of the screen, and the polygon does not respond accordingly when I zoom in and zoom out. It just stays at the top left(provided I just draw it at (0,0)), and at that same size, regardless of zooming.

    qreal rad = (-angle / 180) * PI;
    qreal sina = std::sin(rad);
    qreal cosa = std::cos(rad);
    QTransform translationTransform(1, 0, 0, 1, point.x(), point.y());
    QTransform rotationTransform(cosa, sina, -sina, cosa, 0, 0);
    QTransform scalingTransform(1, 0, 0, 1, 0, 0);
    QTransform transformMatrix = translationTransform * rotationTransform * scalingTransform;
    painter->setWorldTransform(transformMatrix);
    painter->drawPath(myPath); //myPath is a QPainterPath of lines



    However, if I use QPainter::translate/rotate/scale, it reponds with the zoom, and it is not stuck at the top-left, but it does not draw the polygons as what I wanted.

    painter->translate(point);
    painter->rotate(-angle);
    painter->drawPath(myPath); //myPath is a QPainterPath of lines



    I have searched in forums, nothing much on this topic. Read through documents, still do not understand how to solve the problem, but I think it has something to do with the coordinate system (before QTransform, (0,0) is at screen's midpoint; after QTransform, (0,0) is at screen's top-left).

    I've been stuck here for more than a week already... Any idea on anything that I missed out?

    Thanks in advance.

  2. #2

    Default Re: Zooming does not work after QTransform

    Hi,

    I solved it. For those who have the same problem, i just added a 'true' in a function call...

    painter->setWorldTransform(transformMatrix, true);

Similar Threads

  1. How to construct a QTransform?
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2011, 15:20
  2. Using QTransform to map the mouse
    By Cruz in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2010, 08:47
  3. QTransform()
    By mkind in forum Newbie
    Replies: 0
    Last Post: 19th February 2010, 21:45
  4. QTransform + drawLine ?
    By verburg in forum Qt Programming
    Replies: 0
    Last Post: 23rd January 2009, 00:32
  5. QTransform vs QMatrix
    By maverick_pol in forum Qt Programming
    Replies: 7
    Last Post: 4th October 2007, 10:53

Tags for this Thread

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.