Results 1 to 6 of 6

Thread: Rotating a rectangle about its origin

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: Rotating a rectangle about its origin

    Finally i am able to rotate the rectangle about its origin.Below is the working code.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Widget : public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7. void paintEvent(QPaintEvent * event)
    8. {
    9. QRect rect(0,0,150,100);
    10. QPainter painter(this);
    11. painter.translate(150,150);
    12. painter.drawRect(rect);
    13. static qreal degree=0;
    14. painter.rotate(++degree);
    15. painter.translate(-rect.width()/2,-rect.height()/2);
    16. painter.drawRect(rect);
    17. painter.drawPoint(rect.center());
    18.  
    19. QTimer::singleShot(0,this, SLOT(update()));
    20. }
    21. };
    22.  
    23. int main(int argc, char *argv[])
    24. {
    25. QApplication a(argc, argv);
    26. a.setStyleSheet("QWidget{background: white}");
    27. Widget w;
    28. w.show();
    29. return a.exec();
    30. }
    31.  
    32. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    It's strictly about doing anything concerning application logic in a paint event
    Please tell the mistake in my program and how to avoid it.How would u have killed it.
    Last edited by babu198649; 25th October 2008 at 12:34.

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.