[Qt-interest] How to rotate a rectangle with QPainter?

vronskij vronskij at gmail.com
Wed Aug 19 13:14:54 CEST 2009


Hi,

I want to rotate a rectangle. It middle of the rectangle should stay
in the middle of the window.

The rotate() method rotates the whole coordinate system. In other
words, using this
method, the rectangle rotates along its upper left point. I want to
rotate the rectangle
along its middle point.

How to achieve this?

Thanks,

jan bodnar

The code looks like:

       rotate++

       int w = width()
       int h = height()

       painter.translate(w/2, h/2)
       painter.rotate(rotate)
       painter.drawRect(QRect(0, 0, 200, 80))



More information about the Qt-interest-old mailing list