Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Grouping drawtext() or changing them to path to group them
Qt 6.12 LTS is out! See what's new in the release blog

Grouping drawtext() or changing them to path to group them

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 1 Posters 663 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GilboonetG Offline
    GilboonetG Offline
    Gilboonet
    wrote on last edited by
    #1

    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.

    GilboonetG 1 Reply Last reply
    0
    • GilboonetG Offline
      GilboonetG Offline
      Gilboonet
      wrote on last edited by
      #5

      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));
      }
      
      1 Reply Last reply
      0
      • GilboonetG Gilboonet

        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.

        GilboonetG Offline
        GilboonetG Offline
        Gilboonet
        wrote on last edited by
        #2

        @Gilboonet Apparently, what I need to use is QPainterPath, https://doc.qt.io/qt-6/qpainterpath.html#addText.

        GilboonetG 1 Reply Last reply
        0
        • GilboonetG Gilboonet

          @Gilboonet Apparently, what I need to use is QPainterPath, https://doc.qt.io/qt-6/qpainterpath.html#addText.

          GilboonetG Offline
          GilboonetG Offline
          Gilboonet
          wrote on last edited by
          #3

          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.

          GilboonetG 1 Reply Last reply
          0
          • GilboonetG Gilboonet

            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.

            GilboonetG Offline
            GilboonetG Offline
            Gilboonet
            wrote on last edited by
            #4

            Here's what I have
            Screenshot_20230612_222555.png
            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.

            1 Reply Last reply
            0
            • GilboonetG Offline
              GilboonetG Offline
              Gilboonet
              wrote on last edited by
              #5

              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));
              }
              
              1 Reply Last reply
              0
              • GilboonetG Gilboonet has marked this topic as solved on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt
              • Unsolved