How to change font weight at various locations within a QTextEdit
-
good found.
well a newline is \n\r on windows.
so maybe thats why with 2. -
Hi folks !
I open this topic again because I get a weird thing.
Here is what I wrote:void Tools::toHtml(QPlainTextEdit* edit, int location, int charcount, int red, int green, int blue, int fontsize, bool bold, bool underlined) { QTextCursor cursor(edit->document()); QString highlight; QString sfont_beg = "<FONT "; QString sfont_end = "</FONT>"; QString scolor = "color=#" + toHexString(red) + toHexString(green) + toHexString(blue) + " "; QString sbold = "span style=font-weight:bold "; QString sunderlined = "span style=text-decoration:underline "; QString ssize = "size=" + QString::number(fontsize) + ">"; QString sHtml; cursor.setPosition(location, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, charcount); highlight = cursor.selectedText(); sHtml = sfont_beg + scolor.toUpper(); if (bold) sHtml = sHtml.append(sbold); if (underlined) sHtml = sHtml.append(sunderlined); sHtml = sHtml + ssize + highlight + sfont_end; cursor.insertHtml(sHtml); }
I call the function here:
m_tools->toHtml(m_descriptionPlainTextEdit, 0, 17 + msg_description.length(), 0, 133, 255, 25, false, false);
The title that has to be highlighted in blue has a length equal to 17 + msg_description.length().
Everything perfectly runs the first time, not the following ones : all the text in the text edit is highlighted in blue.
I don't see any trouble.PS: the text edit is cleared each time.
Many thanks for help !
-
Hi
ïf you put edit->clear();
in top, it really should do the same each time. -
@mrjj Hi ! What do you mean in top ? In toHtml ? It would delete all the content.
-
@mrjj Hi ! What do you mean in top ? In toHtml ? It would delete all the content.
@mulfycrowh
Well you said
"PS: the text edit is cleared each time."
So I assumed you meant pr call to the function.If all becomes blue it sounds like all is one paragraph.
You might need to use <p > </p> if the end result is something like
-
@mulfycrowh
Well you said
"PS: the text edit is cleared each time."
So I assumed you meant pr call to the function.If all becomes blue it sounds like all is one paragraph.
You might need to use <p > </p> if the end result is something like
@mrjj The idea sounds interesting. I'll test it.
But why everything OK the first time and all the text blue with big size font the other ones ?
It acts as the QTextEdit keeps backup of something.
Thanks again ! -
@mrjj The idea sounds interesting. I'll test it.
But why everything OK the first time and all the text blue with big size font the other ones ?
It acts as the QTextEdit keeps backup of something.
Thanks again !- But why everything OK the first time and all the text blue with big size font the other ones ?
I have not check output of the code but I assume it becomes
one big paragraph and therefore it is all blue.But only way to tell is to see the generated HTML. step by step.
-
I added the following lines to toHtml ant it runs !
cursor.setPosition(charcount, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, edit->document()->characterCount()); highlight = cursor.selectedText(); sHtml = "<FONT face=\"Arial\" font-weight=\"normal\" COLOR=#000000 size=\"3\">" + highlight + "</FONT>"; cursor.insertHtml(sHtml);
-
Nevertheless, I do not understand size=3 because, in the constructor I wrote:
font.setPointSize(10);
Why 3 instead 10 ?
3 gives the same size.
-
Nevertheless, I do not understand size=3 because, in the constructor I wrote:
font.setPointSize(10);
Why 3 instead 10 ?
3 gives the same size.
@mulfycrowh
Not sure what unit "size" is in. Could be an index to a list.
so its size "3". -
@mulfycrowh
Not sure what unit "size" is in. Could be an index to a list.
so its size "3".@mrjj Thank you for everything !