Results 1 to 6 of 6

Thread: How do I rotate a QPolygon

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How do I rotate a QPolygon

    I'm having a problem rotating polygon. Below is the code how I tried. Please guide me. Thank you.

    Qt Code:
    1. void Dialog::draw_needle()
    2. {
    3. QPolygon needle;
    4. needle.setPoints(4, 0,7, 14,0, 160,7, 14,14);
    5. needle.translate((this->width()/2), (this->height()/2)+30 );
    6.  
    7. QPainter painter(this);
    8. painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    9. painter.setBrush(QColor(122, 163, 39));
    10. painter.drawConvexPolygon(needle);
    11. painter.rotate(45);
    12. }
    13.  
    14. void Dialog::paintEvent(QPaintEvent *event)
    15. {
    16. draw_dial();
    17. draw_needle();
    18. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How do I rotate a QPolygon

    Qt Code:
    1. painter.drawConvexPolygon(needle);
    2. painter.rotate(45);
    To copy to clipboard, switch view to plain text mode 
    You need to rotate first, then draw:
    Qt Code:
    1. painter.rotate(45);
    2. painter.drawConvexPolygon(needle);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I rotate a QPolygon

    It's working now. But my rotate function is drawing the polygon in opposite direction. I gave angle of 90 degrees, but the angle it is drawing the polygon with -90 degrees. Any help here please.

    Qt Code:
    1. painter.translate((this->width()/2), (this->height()/2)+30);
    2. painter.rotate(90);
    3. painter.drawPolygon(needle, Qt::OddEvenFill);
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 29th December 2011 at 06:21.

  4. #4
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I rotate a QPolygon

    painter.rotate( -90 );

  5. #5
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I rotate a QPolygon

    Dude, I tried that. But, I want to know the reason why it's taking clockwise, and not the conventional trigonometric way.

  6. #6
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: How do I rotate a QPolygon

    If you want the reason, ask for the reason... You must have checked the documentation which says that rotate "Rotates the coordinate system the given angle clockwise". That is, it rotates the world where the polygons live. When you specify a polygon, you just specify points in the rotated coordinate system, not rotated coordinates. Completely conventional, but not perhaps completely documented.

Similar Threads

  1. Is QPolygon really just a vector of points?
    By taraj in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2011, 00:08
  2. How to use a QPolygon as a Pushbutton?
    By Manish.S in forum Newbie
    Replies: 4
    Last Post: 6th December 2010, 11:57
  3. QPainterPath and QPolygon
    By Muz in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2009, 08:16
  4. What really is a QPolygon...
    By giusepped in forum Qt Programming
    Replies: 11
    Last Post: 14th January 2009, 07:57
  5. QPolygon rotate
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2007, 12:18

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.