Can QPainter.drawText rotate text ?
-
wrote on 7 Jun 2023, 09:27 last edited by
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 ? -
@Gilboonet yes, that is indeed the way to do it. Except that you should likely put the rotate and translate before the drawText
wrote on 7 Jun 2023, 12:08 last edited by Gilboonet 6 Jul 2023, 12:09@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(); }
-
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 ?wrote on 7 Jun 2023, 10:01 last edited by@Gilboonet Apparently I need to use
painter.save(); painter.drawText(0,0, string); painter.rotate(); painter.translate(x, y); painter.restore();
-
@Gilboonet Apparently I need to use
painter.save(); painter.drawText(0,0, string); painter.rotate(); painter.translate(x, y); painter.restore();
wrote on 7 Jun 2023, 10:47 last edited by TomZ 6 Jul 2023, 10:48@Gilboonet yes, that is indeed the way to do it. Except that you should likely put the rotate and translate before the drawText
-
@Gilboonet yes, that is indeed the way to do it. Except that you should likely put the rotate and translate before the drawText
wrote on 7 Jun 2023, 12:08 last edited by Gilboonet 6 Jul 2023, 12:09@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(); }
-
4/4