QTextEdit make text bold
-
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?
-
Hi,
Can you compare the code you are using with the Rich Text Editor example ?
-
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.
-
And what if you use the exact same code as the example ?
-
Using the exact same code gives the same result.
-
@legitnameyo it might be a silly question, but have you tried another font?
-
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...
-
@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. -
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.
-
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.
-
Hi
Ok so its global for Qt at least.
What about other non Qt apps ? Can they do bold? -
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?
-
@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? -
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.
-
@legitnameyo
Hi
Please see
https://bugreports.qt.io/browse/QTBUG-69955I 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. -
I can't seem to find a qt 5.12.1.dmg file anywhere on qt's website, where exactly is it located?
-
@legitnameyo it is not released yet, you can probably find a snapshot or use the online installer.
-
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.)
-
@legitnameyo
What about in the maintenance tool ?
on windows, its located in the base Qt folder.
I assume it somewhat the same on macOS.