Grouping drawtext() or changing them to path to group them
-
I'm currently improving the svg output of my qt C++ application. The produced svg will be used by a cutting machine, so I have several paths. I managed to group the paths so that now I have one path for each kind of job (cut, fold, trace). But I also have texts and I didn't see what I could do to have them grouped too. Is there a way to have painter.drawText() changed to paths ? If there is nothing possible with drawText() I can use a custom set of path to replace the text that I already use on html/js version of my application.
-
With mapping from a QTransform object I managed to group those text paths.
if (doSVG) { QPainterPath pp; pp.addText(- ti->boundingRect().width()/2, -2, fNum, QString::number(n)); QTransform tr; QPointF pt = c.toPointF()+ b.toPointF() +tit->pos(); tr.translate(pt.x(), pt.y()); tr.rotate(radToDeg(ra)); tPath.addPath(tr.map(pp)); } -
I'm currently improving the svg output of my qt C++ application. The produced svg will be used by a cutting machine, so I have several paths. I managed to group the paths so that now I have one path for each kind of job (cut, fold, trace). But I also have texts and I didn't see what I could do to have them grouped too. Is there a way to have painter.drawText() changed to paths ? If there is nothing possible with drawText() I can use a custom set of path to replace the text that I already use on html/js version of my application.
@Gilboonet Apparently, what I need to use is QPainterPath, https://doc.qt.io/qt-6/qpainterpath.html#addText.
-
@Gilboonet Apparently, what I need to use is QPainterPath, https://doc.qt.io/qt-6/qpainterpath.html#addText.
I changed my code to use QPainterPath, that way I now have paths and no more text element, but I'm struggling to group those paths as the last thing that I do with them is a rotation that I do like that :
if (doSVG) { painter.save(); painter.translate(c.toPointF()+ b.toPointF() +tit->pos()); painter.rotate(radToDeg(ra)); QPainterPath pp; pp.addText(- ti->boundingRect().width()/2, -2, fNum, QString::number(n)); painter.drawPath(pp); painter.restore(); }What I would like to to is add the rotated path to a QPainterPath object and only add this WPainterPath once with painter.drawPath() in order to have a path with all the text. But I don't know how to get the rotated path as painter.drawPath() is a void function and I didn't find any function related to rotation into QPainterPath class.
-
I changed my code to use QPainterPath, that way I now have paths and no more text element, but I'm struggling to group those paths as the last thing that I do with them is a rotation that I do like that :
if (doSVG) { painter.save(); painter.translate(c.toPointF()+ b.toPointF() +tit->pos()); painter.rotate(radToDeg(ra)); QPainterPath pp; pp.addText(- ti->boundingRect().width()/2, -2, fNum, QString::number(n)); painter.drawPath(pp); painter.restore(); }What I would like to to is add the rotated path to a QPainterPath object and only add this WPainterPath once with painter.drawPath() in order to have a path with all the text. But I don't know how to get the rotated path as painter.drawPath() is a void function and I didn't find any function related to rotation into QPainterPath class.
Here's what I have

There's one path with all red lines (for cut), one path for --- maroon (mountain) folds, one path for -.- green (valley) folds, and 49 paths for the texts (numbers). What I want to have is only one path with all the numbers, but if I want to have them rotated like that I need to use painter.drawpath() for each of them. -
With mapping from a QTransform object I managed to group those text paths.
if (doSVG) { QPainterPath pp; pp.addText(- ti->boundingRect().width()/2, -2, fNum, QString::number(n)); QTransform tr; QPointF pt = c.toPointF()+ b.toPointF() +tit->pos(); tr.translate(pt.x(), pt.y()); tr.rotate(radToDeg(ra)); tPath.addPath(tr.map(pp)); } -
G Gilboonet has marked this topic as solved on