QSyntaxHighlighter - no bold text?
-
Hi,
I'm fiddling with SyntaxHighlighter. My regex seem to work, as editor shows the colors. But Fontweight bold has no visual difference to plain text.
I tried QTextEdit as well as QPlainTextEdit - no difference.
I also tried different fonts, in case the default font does not support bold characters ...
Even with Font-family "hack" which is used in linux console there is no bold texts in textedit.First I thought, I am doing something wrong, but then I realized, that sample "richtext/syntaxhighlighter" has the same shortcoming.
What can I do to get bold text support?
-
Hi,
I'm fiddling with SyntaxHighlighter. My regex seem to work, as editor shows the colors. But Fontweight bold has no visual difference to plain text.
I tried QTextEdit as well as QPlainTextEdit - no difference.
I also tried different fonts, in case the default font does not support bold characters ...
Even with Font-family "hack" which is used in linux console there is no bold texts in textedit.First I thought, I am doing something wrong, but then I realized, that sample "richtext/syntaxhighlighter" has the same shortcoming.
What can I do to get bold text support?
-
Hi
Use QTextEdit.QPlainTextEdit can only use bold font for all of the text at the same time. It cannot do it on a keyword with SyntaxHighlighter.
It's optimized for speed and hence does not support anything but a single font.- First I thought, I am doing something wrong, but then I realized, that sample "richtext/syntaxhighlighter" has the same shortcoming.
In 5.15.2 on Win 10 it does seem to change
with classFormat.setFontWeight(QFont::Bold); // ON
without classFormat.setFontWeight(QFont::Bold); // OFF
-
Hi,
just verified - and as I already wrote: QTextEdit does not show bold. At linux system, of cause ;)
changed to QTextEdit and for so added text with setText instead of setPlainText.
-
Hi,
just verified - and as I already wrote: QTextEdit does not show bold. At linux system, of cause ;)
changed to QTextEdit and for so added text with setText instead of setPlainText.
@django-Reinhard
Hi
Just tested with Mint linux 18 and Qt 5.9
and bold shows there tooSo What distro and what Qt version are you seeing this ?
-
Hi,
thank you for your attention!
I use debian 11 (bullseye) with qt 5.15.2
I use provided qt-packages from debian - not self compiled.Don't know, whether qtcreator has bold markers in syntax view ...
Here's a sample of qtcreator together with a kde console output, which does support bold markers with the font I use in the above samples
-
Finally got it and it looks like a font issue.
Don't know, whether it is related to the fact, that font files are different for plain/bold ...
I have some windows fonts copied to my linux box and it looks like "Courier10 BT" works fine - even with QPlainTextEdit.I checked it with Qt example and every token is displayed as expected.
So I have to rewind all from QTextEdit to QPlainTextEdit.Using QTextEdit is a real pain :(
I tried to work out what is shown by codeEditor example, but I wasn't successful. Don't know, how to figure out the basic calls like firstVisibleBlock or rectangleForBlock or ...Theres so much, I don't know :(
-
Finally got it and it looks like a font issue.
Don't know, whether it is related to the fact, that font files are different for plain/bold ...
I have some windows fonts copied to my linux box and it looks like "Courier10 BT" works fine - even with QPlainTextEdit.I checked it with Qt example and every token is displayed as expected.
So I have to rewind all from QTextEdit to QPlainTextEdit.Using QTextEdit is a real pain :(
I tried to work out what is shown by codeEditor example, but I wasn't successful. Don't know, how to figure out the basic calls like firstVisibleBlock or rectangleForBlock or ...Theres so much, I don't know :(
Hi
Yes the QTextEdit API is a bit complicated.
Wht are you trying to do with it ? -
I wanted a combination of syntaxcoloring and codeeditor examples. When you suggested, that QPlainTextEdit could not distinct between bold and plain, I started to migrate to QTextEdit.
But then I had to realize, the QTextDocument does not provide the basics that QPlainTextEdit does.No problem, I have it working now.
In case you're interested: https://github.com/DjangoReinhard/QtUi.git -
I wanted a combination of syntaxcoloring and codeeditor examples. When you suggested, that QPlainTextEdit could not distinct between bold and plain, I started to migrate to QTextEdit.
But then I had to realize, the QTextDocument does not provide the basics that QPlainTextEdit does.No problem, I have it working now.
In case you're interested: https://github.com/DjangoReinhard/QtUi.gitHi
I'm very interested as I thought it was impossible with
QPlainTextEdit to alter any of the blocks to have other formatting but it sounds like
you actually did that.Well QPlainTextEdit has a higher level interface than QTextDocument where you really have
to fiddle around with internal building blocks.thx for the code :)