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. I want to change the line spacing for fonts or text
Forum Updated to NodeBB v4.3 + New Features

I want to change the line spacing for fonts or text

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 7.3k 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.
  • K Offline
    K Offline
    kenchan
    wrote on last edited by
    #1

    Hi, I want to draw blocks of text in a QGraphicsScene and I want to have variable line spacing. I can't find any functions to change this property of a font. Is this possible???

    Currently I draw each line of text separately and do the spacing myself... It would be nice if Qt could handle this kind of thing by being able to change the line spacing or leading or something.

    Is there a way to do this now with simple or rich text?
    How does one go about asking for a new feature like this to be added to Qt??

    Thanks.

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

      Hi,

      If I understood you correctly (I suppose you are using a QGraphicsTextItem) you should have a look at QTextDocument, QTextCursor and related classes to achieve what you want.

      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
      • K Offline
        K Offline
        kenchan
        wrote on last edited by
        #3

        Thank you, I am currently using a QGraphicsSimpleTextItem but I can change that to something else if needed. I will look at those classes.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          Using QTextDocument (which i also recommend) you have to do this by yourself.
          Qt unfortunately doesn't provide an simple property for this:
          @
          QTextDocument* doc = ...;
          QTextFrame * root = doc->rootFrame();
          QTextFrame::iterator it;
          for( it = root->begin(); !(it.atEnd()); ++it )
          {
          QTextBlock block = fit.currentBlock();
          block.blockFormat().setLineHeight(5, QTextBlockFormat::LineDistanceHeight); //set spacing of 5 pixels
          }
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • K Offline
            K Offline
            kenchan
            wrote on last edited by
            #5

            Thank you for the sample code raven-worx . I am looking at using this for my text items.

            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