[SOLVED]Again with arrow head, QTransform.
Hello,
Here is my arrow head, a rhomb:

- QPolygonF arrowHead;
- arrowHead.push_back(arrowHead.first());
With QTransform::translate we replace QPointF(0, 0) with (intersectPoint.x(), intersectPoint.y()) and with QTransform::rotate we rotate the rhomb to the line angle (centerLine.angle() + 90). But when I am rotating the line, the rhomb rotates in the opposite of my line angle.
- QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(centerLine.angle() + 90, Qt::ZAxis);
So, I tried this piece of code, and works, the rhomb angle is the same angle that line angle. But the rhomb is located at Point(0, 0).
Finally, two codes below do not work, both the angle and position is inconsistent. I think that the only must be inverted() is the angle and not the QTransform at all.
- QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(centerLine.angle() + 90, Qt::ZAxis).inverted();
- transform = transform.translate(intersectPoint.x(), intersectPoint.y());
Thanks, Mario.
1 reply
I apologize, after I wrote above post, I realized that I must invert/normalize the angle by myself. I don’t know why inverted() function inverted all QTransform, so below is the final (or part of) code:
- qreal angle = centerLine.angle();
- if (centerLine.dy() >= 0 || centerLine.dy() <= 0) {
- angle = -angle;
- }
- QPolygonF arrowHead;
- arrowHead.push_back(arrowHead.first());
- QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(angle - 90, Qt::ZAxis);
Note at the 15 line we subtract 90 to angle (angle – 90).
Now we can add any types of arrow heads:
- QPolygonF arrowHead;
- //arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
- arrowHead.push_back(arrowHead.first());
- arrowHead.push_back(arrowHead.first());
- QPolygonF arrowHead;
- //arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
- //arrowHead.push_back(arrowHead.first());
- arrowHead.push_back(arrowHead.first());
…..
Thanks, Mario.
You must log in to post a reply. Not a member yet? Register here!

