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. Rotate Each Character in a Text (drawText)
Forum Update on Monday, May 27th 2025

Rotate Each Character in a Text (drawText)

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 1.2k 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.
  • A Offline
    A Offline
    Adam Crowe
    wrote on last edited by
    #1

    Hello,

    I need to draw some text in almost a Japanese style vertical writing (column) but in the left-to-right direction like so:

    alt text

    Can someone please suggest a reasonable way to do this with drawText?

    Many many thank yous!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the top of my head, I would go with using QPainter::rotate to draw the text vertically in a QImage and the rotate that image.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Adam Crowe
        wrote on last edited by
        #3

        I've actually done that before when this app was written in C# on Windows. I effectively measured the QRect of each letter/character, make a QImage for it, rotated it, and draw that image on to the main canvas. Apart from being quite cumbersome, the main problem is that the Image rasterises the text which makes it quite ugly in small font sizes.

        I was hoping for a more direct to main canvas approach.

        That example image I added was done in Photoshop with two clicks but they obviously have a crazy powerful font drawing engine in there.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How are you going to use that text ? QWidget ? QGraphicsView ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            How are you going to use that text ? QWidget ? QGraphicsView ?

            A Offline
            A Offline
            Adam Crowe
            wrote on last edited by
            #5

            @SGaist QGraphicsView and eventually with QPrinter.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              In that case, you should be able to just rotate the item itself after having drawn the text vertically.

              Are you using a QGraphicsTextItem ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                In that case, you should be able to just rotate the item itself after having drawn the text vertically.

                Are you using a QGraphicsTextItem ?

                A Offline
                A Offline
                Adam Crowe
                wrote on last edited by
                #7

                @SGaist I'm not using a QGraphicsTextItem but I can. Would it make it easier?

                This would involve a hell of a lot of rotations and translations to position the text and maintain centre alignment 🤯

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Can you show an example of the result you are looking for ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Can you show an example of the result you are looking for ?

                    A Offline
                    A Offline
                    Adam Crowe
                    wrote on last edited by
                    #9

                    @SGaist It's exactly like how that image in the original post is.

                    This is what I've done on Windows with C# and the equivalent of QImage:

                    alt text

                    The normal left-to-right text is drawn with the equivalent of drawText and it scales and renders perfectly regardless of scale level or device DPI; but because of the QImage, the rotated vertical writing text rasterises and gets pixilated if it's too small or when printing.

                    In this code, every character is measured, drawn centre-aligned, rotated, copied to the main canvas, and so on. Doing it like this with a QImage like you suggested is actually simpler than worrying about the math of rotating and transferring the whole canvas to position each character.

                    I was just hoping there was a smarter solution than this. Japanese is essentially written in vertical writing (literal translation of "Tategaki") so I thought there would be a common efficient solution to this problem.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Just had an untested silly idea, why not have your vertical text be a string where each letter is follow by a line break ? Then you would only have to rotate the painter and not have to do more complicated stuff.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply
                      2
                      • SGaistS SGaist

                        Just had an untested silly idea, why not have your vertical text be a string where each letter is follow by a line break ? Then you would only have to rotate the painter and not have to do more complicated stuff.

                        A Offline
                        A Offline
                        Adam Crowe
                        wrote on last edited by
                        #11

                        @SGaist

                        alt text

                        Why didn't I think of that?!

                        1 Reply Last reply
                        0

                        • Login

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