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

QTextEdit make text bold

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 5 Posters 12.5k 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.
  • L Offline
    L Offline
    legitnameyo
    wrote on last edited by
    #1

    I've added a click action function and made it so the button background color changes, to indicate that bold is activated, and added this code

    void Testt::on_bold_pressed()
    {
        if(!bold_pressed) {
            ui->text_toggle_bold->setStyleSheet("QPushButton { color: black; font: 13px;font-weight: 600;background-color: #e6e6e6;border: 1px solid #cccccc; border-top-left-radius: 9px;border-bottom-left-radius: 9px;height: 10px;width: 10px;} QPushButton:hover {background-color: #e6e6e6;}");
    
    
            QTextCharFormat format;
            format.setFontWeight(QFont::Bold);
    
            QTextCursor cursor = ui->textEdit->textCursor();
            cursor.mergeCharFormat(format);
    
    
            QTextCharFormat fmt;
            fmt.setFontWeight(QFont::Bold);
             mergeFormatOnWordOrSelection(fmt);
    } else { ... }
    

    but nothing happens! I've tried identical stuff with italic (fmt.setFontItalic(true) thing) and that works. Is there something wrong with my "make bold" function?

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

      Hi,

      Can you compare the code you are using with the Rich Text Editor example ?

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

        What is there to compare? I use the same code but added:

        QTextCharFormat format;
         format.setFontWeight(QFont::Bold);
        
        QTextCursor cursor = ui->textEdit->textCursor();
        cursor.mergeCharFormat(format);
        
        

        to make the highlighted text bold as well. The same technique used in my "make bold" code is the same code that I use, and that work, with all the other formats such as italic and underscore. The only difference between, for example, the italic function and bold is that I am not setting the font weight, but rather enabling italic styling.

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

          And what if you use the exact same code as the example ?

          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

            Using the exact same code gives the same result.

            aha_1980A 1 Reply Last reply
            0
            • L legitnameyo

              Using the exact same code gives the same result.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @legitnameyo it might be a silly question, but have you tried another font?

              Qt has to stay free or it will die.

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

                I've tried quite a number of different fonts, and none of them works with bold. I also added some code so that the text changes to both italic and bold, but the text only changes to italic for my "make bold" function. Then I thought, do I actually change the font weight? I added a log function and the answer is yes, I change the font weight but it still wont show up in QTextEdit when I run the program and write in the text edit window...

                mrjjM 1 Reply Last reply
                0
                • L legitnameyo

                  I've tried quite a number of different fonts, and none of them works with bold. I also added some code so that the text changes to both italic and bold, but the text only changes to italic for my "make bold" function. Then I thought, do I actually change the font weight? I added a log function and the answer is yes, I change the font weight but it still wont show up in QTextEdit when I run the program and write in the text edit window...

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

                  @legitnameyo
                  Hi
                  So did you try the sample @SGaist linked ?
                  http://doc.qt.io/qt-5/qtwidgets-richtext-textedit-example.html
                  it would be interesting to know if bold works there.
                  Just takes a moment to test and tell us if its a Qt/system thing or
                  local to your code.

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

                    For some weird reason it's global, system wide. It doesn't matter if I use the rich text edit example or some other project, bold doesn't work on my system with QT QTextEdit.

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

                      I'm using Qt Creator 4.8.0, Based on Qt 5.12.0 (Clang 10.0 (Apple), 64 bit) on MacBook Air with macOS Mojave. I've not had this issue before. It has worked but somewhere along the way it stopped working.

                      mrjjM 1 Reply Last reply
                      0
                      • L legitnameyo

                        I'm using Qt Creator 4.8.0, Based on Qt 5.12.0 (Clang 10.0 (Apple), 64 bit) on MacBook Air with macOS Mojave. I've not had this issue before. It has worked but somewhere along the way it stopped working.

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

                        Hi
                        Ok so its global for Qt at least.
                        What about other non Qt apps ? Can they do bold?

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

                          Yes, not being able to see bold text is exclusive to my Qt apps. I get these project errors as well:

                          Project WARNING: Qt has only been tested with version 10.13 of the platform SDK, you're using 10.14.
                          Project WARNING: This is an unsupported configuration. You may experience build issues, and by using
                          Project WARNING: the 10.14 SDK you are opting in to new features that Qt has not been prepared for.
                          Project WARNING: E.g., 10.14 enables dark mode and layer-backed views, which Qt 5.11 does not support.
                          Project WARNING: Please downgrade the SDK you use to build your app to version 10.13, or configure
                          Project WARNING: with CONFIG+=sdk_no_version_check when running qmake to silence this warning.
                          

                          Is this an issue regarding my os?

                          JonBJ 1 Reply Last reply
                          0
                          • L legitnameyo

                            Yes, not being able to see bold text is exclusive to my Qt apps. I get these project errors as well:

                            Project WARNING: Qt has only been tested with version 10.13 of the platform SDK, you're using 10.14.
                            Project WARNING: This is an unsupported configuration. You may experience build issues, and by using
                            Project WARNING: the 10.14 SDK you are opting in to new features that Qt has not been prepared for.
                            Project WARNING: E.g., 10.14 enables dark mode and layer-backed views, which Qt 5.11 does not support.
                            Project WARNING: Please downgrade the SDK you use to build your app to version 10.13, or configure
                            Project WARNING: with CONFIG+=sdk_no_version_check when running qmake to silence this warning.
                            

                            Is this an issue regarding my os?

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

                            @legitnameyo
                            You should maybe take a look at https://forum.qt.io/topic/98943/qpainter-drawtext-bold/5. That user is also experiencing Bold problems under MacOS, maybe your problem is related?

                            mrjjM 1 Reply Last reply
                            3
                            • JonBJ JonB

                              @legitnameyo
                              You should maybe take a look at https://forum.qt.io/topic/98943/qpainter-drawtext-bold/5. That user is also experiencing Bold problems under MacOS, maybe your problem is related?

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

                              @JonB
                              Good call, but turn out to just be QPainter issue and
                              the Rich Text sample did work.

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

                                I tried running an old QTextEdit project with no issues that had a QTextEdit and a make bold funciton, but it doesn't work anymore there either! Is there another way to set text to bold?

                                Edit: When I changed the default html that you see after starting the program to some bold text, the text stays bold. I can display bold text, but I can't edit text to become bold. I can only pre-define bold text, not create bold text nor remake normal text to bold text.

                                Edit2: After double pressing the QTextEdit in Qt creator I get up the "change HTML" window and there I can define some bold text. After creating some bold text, then writing normal text and then compile and run the program I can write and change text to bold as I please. What I am trying to say is that, when I already have bold text AND normal text in the program, the bold function works. The issue then is that there is a slight delay between when I write and when the text shows up on the screen! I've created a thread about this issue earlier but to no success.

                                mrjjM 1 Reply Last reply
                                0
                                • L legitnameyo

                                  I tried running an old QTextEdit project with no issues that had a QTextEdit and a make bold funciton, but it doesn't work anymore there either! Is there another way to set text to bold?

                                  Edit: When I changed the default html that you see after starting the program to some bold text, the text stays bold. I can display bold text, but I can't edit text to become bold. I can only pre-define bold text, not create bold text nor remake normal text to bold text.

                                  Edit2: After double pressing the QTextEdit in Qt creator I get up the "change HTML" window and there I can define some bold text. After creating some bold text, then writing normal text and then compile and run the program I can write and change text to bold as I please. What I am trying to say is that, when I already have bold text AND normal text in the program, the bold function works. The issue then is that there is a slight delay between when I write and when the text shows up on the screen! I've created a thread about this issue earlier but to no success.

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

                                  @legitnameyo
                                  Hi
                                  Please see
                                  https://bugreports.qt.io/browse/QTBUG-69955

                                  I think that is what we are seeing.

                                  Also check out
                                  https://forum.qt.io/topic/98943/qpainter-drawtext-bold as he
                                  seemingly has the same issue as you.

                                  Update:
                                  He installed 5.12.1 snapshot and Bold now works for him.
                                  If possible, please try that.

                                  1 Reply Last reply
                                  2
                                  • L Offline
                                    L Offline
                                    legitnameyo
                                    wrote on last edited by
                                    #17

                                    I can't seem to find a qt 5.12.1.dmg file anywhere on qt's website, where exactly is it located?

                                    aha_1980A 1 Reply Last reply
                                    0
                                    • L legitnameyo

                                      I can't seem to find a qt 5.12.1.dmg file anywhere on qt's website, where exactly is it located?

                                      aha_1980A Offline
                                      aha_1980A Offline
                                      aha_1980
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      @legitnameyo it is not released yet, you can probably find a snapshot or use the online installer.

                                      Qt has to stay free or it will die.

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

                                        I can't find any "qt 5.12.1 snapshot" .dmg file on the QT wesbite... can anyone give me the link? Also I do not have the "make" command nor the "configure" command, just a heads up! (I don't know why I don't have those commands.)

                                        mrjjM 1 Reply Last reply
                                        0
                                        • L legitnameyo

                                          I can't find any "qt 5.12.1 snapshot" .dmg file on the QT wesbite... can anyone give me the link? Also I do not have the "make" command nor the "configure" command, just a heads up! (I don't know why I don't have those commands.)

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

                                          @legitnameyo
                                          What about in the maintenance tool ?
                                          alt text

                                          on windows, its located in the base Qt folder.
                                          I assume it somewhat the same on macOS.

                                          1 Reply Last reply
                                          2

                                          • Login

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