Results 1 to 4 of 4

Thread: QPaint - Scale

  1. #1
    Join Date
    Apr 2009
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Post QPaint - Scale

    HI,
    i have drawn one polygon using paint eventin QWidget. i have implemented code for zoom in/zoom out using wheelevent like below

    const QPointF points[4]={(100,100),(125,67),(125,99),(100,200)};
    QPaintevent(QPainter painter)
    {
    painter.scale(m_scale,m_scale);
    painter.drawPolygon(points,4);
    }
    wheelevent

    QWheelevent(QWheelEvent *event)
    {
    if(event->delta()>0
    {
    m_scale+=0.5;
    update();
    }

    problem is here it's zooming but position of polygon is shifting right.

    please tell me why it's happening like this.

    thanks in advance

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPaint - Scale

    Scale does ecactly that: it scales all coordinates, this obviously affects both sizes and positions - if the x-offset was at 50, and you scale by factor 2, it will be at position 100. Thus the item moves (on your screen). Relatively to other things you paint (with that painter), it does not move.
    You can readjust that with a call to translate().

    A common "trick" is to first move the origin with translate() and then paint whatever you want relative to your origin, that way if you scale (*after* that translation) only the size will increase, but the origin will remain.

    HTH

  3. #3
    Join Date
    Apr 2009
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Arrow Re: QPaint - Scale

    Relatively to other things you paint (with that painter), it does not move.
    i don't understand what is above sentence mean. Plz explain me. What ever i have drawn using that painter all are changing.

    A common "trick" is to first move the origin with translate() and then paint whatever you want relative to your origin, that way if you scale (*after* that translation) only the size will increase, but the origin will remain.
    that mean we translate to center of window every time constantly are changed to every time

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPaint - Scale

    translate the item in reverse order with the scale factor whenever u scale the item ..
    caduel shows u the
    if the x-offset was at 50, and you scale by factor 2, it will be at position 100.
    u can use this to move back the item to original position using QTranslate
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. Qwt Scale Draw
    By maxpayne in forum Qwt
    Replies: 2
    Last Post: 6th June 2012, 13:01
  2. xBottom Scale Overide
    By baray98 in forum Qwt
    Replies: 7
    Last Post: 7th July 2011, 05:15
  3. Y-Axis Scale Spacing - Newbie Question
    By Rick108 in forum Qwt
    Replies: 3
    Last Post: 13th October 2009, 08:20
  4. Apply different scale on items
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2009, 06:59
  5. Replies: 13
    Last Post: 12th June 2008, 13: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.