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 set tab stop width and space width?
Forum Updated to NodeBB v4.3 + New Features

How to set tab stop width and space width?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 3.3k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Where exactly would you like that to be fixed ?

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

      In a QTextEdit

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

        What font are you using ?

        Can you show how it is looking ?

        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
        • L Offline
          L Offline
          legitnameyo
          wrote on last edited by
          #5

          I am using a regular QTextEdit. There is nothing special in what I am using, no extra code or anything relevant here. I just want to know if someone knows how to change the space to the length of a letter for any given font AND how to change the tab to become four letters in length/width whatever. Or if anyone knows any example of this.

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

            So something like QFont::setLetterSpacing ?

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

            JonBJ 1 Reply Last reply
            1
            • SGaistS SGaist

              So something like QFont::setLetterSpacing ?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #7

              @SGaist
              I could be wrong, but for whatever reason I think the OP is asking how to set just the width of the space character in a font. Not the spacing between every touching letter. This sounds more like QFont::setWordSpacing(), but that still won't achieve what I think he wants. I don't really understand --- if you're trying to "line things up" you'll only achieve that in a fixed font, sounds like the OP is talking about a proportional one....

              1 Reply Last reply
              0
              • L Offline
                L Offline
                legitnameyo
                wrote on last edited by
                #8

                My space is half the width of a letter, which messes things up. How do I make a space character the width of a letter? This "the space is only 0.5 width" is consistent over most fonts I try, so I am guessing my space is only "worth" 0.5 width, just like my tab is worth 8 width, but I want 4.

                J.HilkJ JonBJ 2 Replies Last reply
                0
                • L legitnameyo

                  My space is half the width of a letter, which messes things up. How do I make a space character the width of a letter? This "the space is only 0.5 width" is consistent over most fonts I try, so I am guessing my space is only "worth" 0.5 width, just like my tab is worth 8 width, but I want 4.

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #9

                  @legitnameyo
                  You'll have to use a monospaced font, for example: Courier, Courier New, Lucida Console, Monaco, and Consolas

                  Besides that you can go the overly complicated route of making your own QTextEdit, were you write your own paintEvent function to space the drawing of each char.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  4
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #10

                    Hi

                    To change tab value , you can do

                      QFontMetricsF fm (ui->textEdit->font());
                      auto stopWidth = tabstop * fm.width(' ');
                      ui->textEdit->setTabStopWidth(ceil(stopWidth));
                    
                    

                    As far as i know, you cannot change the space width. However, you
                    can change space between letters and words so that should be enough to
                    line stuff up.

                    1 Reply Last reply
                    4
                    • L legitnameyo

                      My space is half the width of a letter, which messes things up. How do I make a space character the width of a letter? This "the space is only 0.5 width" is consistent over most fonts I try, so I am guessing my space is only "worth" 0.5 width, just like my tab is worth 8 width, but I want 4.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #11

                      @legitnameyo
                      One more time: as @J-Hilk and I have said, you'll never get things to line up perfectly if you do not use a fixed/monospaced font.

                      1 Reply Last reply
                      5

                      • Login

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