Copying and rotating a polygon
Unsolved
General and Desktop
-
Hi all. I need to draw a wind turbine for later manipulations with it:
So far I've got something like this:void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setPen(Qt::white); painter.setBrush(Qt::NoBrush); painter.drawRect(362, 500, 55, 25); painter.drawLine(QPointF(372, 500), QPointF(382, 250)); painter.drawLine(QPointF(392, 250), QPointF(407, 500)); painter.drawEllipse(QPoint(387, 235), 15, 15); const QPointF vane1Points[5] = { QPointF(382, 220), QPointF(367, 190), QPointF(382, 90), QPointF(397, 75), QPointF(392, 220) }; painter.drawPolygon(vane1Points, 5); QWidget::paintEvent(event); }
Result:
I just can't seem to find the coordinates for the other two blades. Is there some way to copy an existing polygon and rotate it? For example, 90 degrees counterclockwise for the blade on the left.
-
Hi,
Why not rotate the painter and repaint the polygon you have already defined ?
-
@SGaist You mean something like that?
void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setPen(Qt::white); painter.setBrush(Qt::NoBrush); painter.drawRect(362, 500, 55, 25); painter.drawLine(QPointF(372, 500), QPointF(382, 250)); painter.drawLine(QPointF(392, 250), QPointF(407, 500)); painter.drawEllipse(QPoint(387, 235), 15, 15); QPolygonF vane1; vane1.append(QPointF(382, 220)); vane1.append(QPointF(367, 190)); vane1.append(QPointF(382, 90)); vane1.append(QPointF(397, 75)); vane1.append(QPointF(392, 220)); painter.drawPolygon(vane1); QTransform transform; transform.rotate(-90); painter.save(); painter.setTransform(transform); painter.drawPolygon(vane1); painter.restore(); QWidget::paintEvent(event); }
It's a little strange because it should work according to Qt documentation, but it doesn't work for me. Result the same. What did I do wrong?