Can QPainter.drawText rotate text ?
-
I'm exporting the output of my application to a svg file using QSvgGenerator and QPainter. It goes well for the lines and paths, but I also need to output rotated text and I didn't find anything that allow me do to that.
Here is what I managed to do...
For the text output my application uses QGraphicsSimpleTextItem and setRotation() on it, and painter.drawText(). Is it possible to create a svg file having text tags with rotation transform or do I need to do that by myself ? -
@TomZ Thank you, I follow the order you mentioned and it works fine.
if (doSVG) { painter.setFont(fNum); painter.setPen(pNum); painter.save(); painter.translate(c.toPointF()+ b.toPointF() +tit->pos()); painter.rotate(radToDeg(ra)); painter.drawText(- ti->boundingRect().width()/2, -2, QString::number(n)); painter.restore(); }
-
@Gilboonet Apparently I need to use
painter.save(); painter.drawText(0,0, string); painter.rotate(); painter.translate(x, y); painter.restore();
-
@Gilboonet yes, that is indeed the way to do it. Except that you should likely put the rotate and translate before the drawText
-
@TomZ Thank you, I follow the order you mentioned and it works fine.
if (doSVG) { painter.setFont(fNum); painter.setPen(pNum); painter.save(); painter.translate(c.toPointF()+ b.toPointF() +tit->pos()); painter.rotate(radToDeg(ra)); painter.drawText(- ti->boundingRect().width()/2, -2, QString::number(n)); painter.restore(); }
-
2/4