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. QSyntaxHighlighter - no bold text?
Forum Updated to NodeBB v4.3 + New Features

QSyntaxHighlighter - no bold text?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 775 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
    django.Reinhard
    wrote on last edited by
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • D django.Reinhard

      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?

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

      @django-Reinhard
      Are you saying this applies only in QSyntaxHighlighter, or to QTextEdits in general, i.e. have you tried bold text in a standalone QTextEdit in a Qt program just to see whether you can see that/it works?

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

        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
        alt text

        without classFormat.setFontWeight(QFont::Bold); // OFF
        alt text

        1 Reply Last reply
        1
        • D Offline
          D Offline
          django.Reinhard
          wrote on last edited by
          #4

          Hi,

          just verified - and as I already wrote: QTextEdit does not show bold. At linux system, of cause ;)

          syntaxHighlighter sample changed to QTextEdit and for so added text with setText instead of setPlainText.

          mrjjM 1 Reply Last reply
          0
          • D django.Reinhard

            Hi,

            just verified - and as I already wrote: QTextEdit does not show bold. At linux system, of cause ;)

            syntaxHighlighter sample changed to QTextEdit and for so added text with setText instead of setPlainText.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @django-Reinhard

            Hi
            Just tested with Mint linux 18 and Qt 5.9
            and bold shows there too

            So What distro and what Qt version are you seeing this ?

            alt text

            alt text

            1 Reply Last reply
            0
            • D Offline
              D Offline
              django.Reinhard
              wrote on last edited by django.Reinhard
              #6

              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
              qtcreator

              1 Reply Last reply
              0
              • D Offline
                D Offline
                django.Reinhard
                wrote on last edited by
                #7

                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 :(

                mrjjM 1 Reply Last reply
                1
                • D django.Reinhard

                  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 :(

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  Yes the QTextEdit API is a bit complicated.
                  Wht are you trying to do with it ?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    django.Reinhard
                    wrote on last edited by
                    #9

                    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

                    mrjjM 1 Reply Last reply
                    1
                    • D django.Reinhard

                      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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi
                      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 :)

                      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