Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can QPainter.drawText rotate text ?
Forum Updated to NodeBB v4.3 + New Features

Can QPainter.drawText rotate text ?

Scheduled Pinned Locked Moved Solved General and Desktop
c++ qtsvg
4 Posts 2 Posters 829 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 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...
    deplUI6.png
    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 ?

    GilboonetG 1 Reply Last reply
    0
    • TomZT TomZ

      @Gilboonet yes, that is indeed the way to do it. Except that you should likely put the rotate and translate before the drawText

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

      @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();
      }
      

      deplUI6a.png

      1 Reply Last reply
      0
      • GilboonetG Gilboonet

        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...
        deplUI6.png
        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 ?

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

        @Gilboonet Apparently I need to use

        painter.save();
        painter.drawText(0,0, string);
        painter.rotate();
        painter.translate(x, y);
        painter.restore();
        
        TomZT 1 Reply Last reply
        0
        • GilboonetG Gilboonet

          @Gilboonet Apparently I need to use

          painter.save();
          painter.drawText(0,0, string);
          painter.rotate();
          painter.translate(x, y);
          painter.restore();
          
          TomZT Offline
          TomZT Offline
          TomZ
          wrote on last edited by TomZ
          #3

          @Gilboonet yes, that is indeed the way to do it. Except that you should likely put the rotate and translate before the drawText

          GilboonetG 1 Reply Last reply
          3
          • TomZT TomZ

            @Gilboonet yes, that is indeed the way to do it. Except that you should likely put the rotate and translate before the drawText

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

            @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();
            }
            

            deplUI6a.png

            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 Extensions
            • Unsolved