How to set tab stop width and space width?
-
For some reason my space width is, with most fonts, half the length of any given letter. This makes it super annoying and difficult to align stuff. I want to have space width and tab stop change depending on the letter width, is there a way to fix this?
-
Hi,
Where exactly would you like that to be fixed ?
-
In a QTextEdit
-
What font are you using ?
Can you show how it is looking ?
-
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.
-
So something like QFont::setLetterSpacing ?
-
@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 likeQFont::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.... -
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.
-
@legitnameyo
You'll have to use a monospaced font, for example: Courier, Courier New, Lucida Console, Monaco, and ConsolasBesides 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.
-
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. -
@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.