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. How to vertical the text and control the line spacing by QPainter::drawText(rect,text)
Forum Updated to NodeBB v4.3 + New Features

How to vertical the text and control the line spacing by QPainter::drawText(rect,text)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 6.2k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    dxwang
    wrote on last edited by
    #1

    I have tried to add '\n' to each character, but I find line spacing is too large, how I can control this line spacing.
    painter->drawText (position,"Qt by \n Trolltech");

    thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      You can try to modify the different parameters of a QFont.

      @
      MyWidget::paintEvent(...)
      {
      QPainter p(this);
      QFont ft = font();
      ft.xxx();
      p.setFont(ft);
      }
      @

      But I'm not 100% sure, whether you can change line height...

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dxwang
        wrote on last edited by
        #3

        thanks Gerolf.
        the font size is 16, it can be changed by user. it means that the text size is ok, just the line spacing is too large,because of "\n". but how to reset line spacing.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          I meant the line height of the font, which is typically ascent + descent + leading (look at QFontMetrics) and which is located in the font properties.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dxwang
            wrote on last edited by
            #5

            ok, I see.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dxwang
              wrote on last edited by
              #6

              I am sorry, I still don’t find that which function can set line spacing in QFont. can someone help me .

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pratik041
                wrote on last edited by
                #7

                [quote author="dxwang" date="1312182018"]I am sorry, I still don’t find that which function can set line spacing in QFont. can someone help me .[/quote]

                Did you find the answer. I am searching something similar ?

                Pratik Agrawal

                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