Results 1 to 4 of 4

Thread: Scaling QPolygon or QPolygonF

  1. #1
    Join Date
    Jul 2011
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Scaling QPolygon or QPolygonF

    Hello,

    I need to scale a polygon.

    write the following

    Qt Code:
    1. QPolygonF qpf=QPolygonF(QPolygon(4,points));
    2. QTransform trans;
    3. trans=trans.scale(1.5,1.5);
    4. QPolygonF qpf2=trans.map(qpf);
    5. path.addPolygon(qpf2);
    To copy to clipboard, switch view to plain text mode 


    for the points:

    Qt Code:
    1. static const int points[8] = {
    2. 10, 80,
    3. 20, 10,
    4. 80, 30,
    5. 90, 70
    6. };
    To copy to clipboard, switch view to plain text mode 

    it generates
    ---15,120--
    ---30,15--
    ---120,45--
    ---135,105--

    thus it moves slightly too.

    is there a way to scale from center?

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QPolygon or QPolygonF

    QTransform is a transformation applied to the coordinate system and not to a single object, such as a polygon. To scale your polygon the way you want, you have to first translate it into the center of the coordinate system. But it#s best if you describe what you really want to do. Do you want to implement some kind of a zooming function?

  3. #3
    Join Date
    Jul 2011
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Scaling QPolygon or QPolygonF

    thanks for reply, yes exactly a zooming function i want.
    can you give some method or class name for
    first translate it into the center of the coordinate system
    thanks

  4. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QPolygon or QPolygonF

    I haven't used it myself yet, but as far as I know the Graphics View Framework comes with a zooming function. Without knowing your requirements and environment, my first advice would be to try and implement your software with this framework.

    If you feel the need to do it yourself with coordinate transformations and widget drawing, then the QTransform is the right thing to use. However, you need to understand exactly what effect coordinate transformations have on what you see on the screen. Basically, you can use the translate() function of QTransform to translate your polygon into the origin, then scale it to the size you want and then you have to translate() it back to the position where you want to see it on the screen and thereby take into account that the coordinate frame has been scale()-d. Please note that scaling the coordinate frame will also change the relative distances between other objects on the screen.

Similar Threads

  1. Limitations to QPolygonF?
    By roband915 in forum Qt Programming
    Replies: 12
    Last Post: 24th May 2011, 14:55
  2. QPolygonF precision?! is it possible?!
    By fatecasino in forum Newbie
    Replies: 11
    Last Post: 27th January 2011, 02:36
  3. What really is a QPolygon...
    By giusepped in forum Qt Programming
    Replies: 11
    Last Post: 14th January 2009, 06:57
  4. Sorting QPolygonF
    By giusepped in forum Qt Programming
    Replies: 3
    Last Post: 7th January 2009, 08:34
  5. Scaling Painter without scaling the coordinate sytem
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2008, 21:30

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.