PDA

View Full Version : Saving html tags in QString and displaying them correctly in a QTextBrowser



b1gsnak3
13th December 2012, 08:37
Hello,

Can anyone tell me how do I save html tags in a QString from a QTextBrowser? Afterwards I will need to put it back in QTextBrowser with the appropiate tags. Getting the text with toPlainText() doesn’t work. Tried with toHtml() and then when putting the qstring back with setHtml() but it doesn’t work. I’m using this to customize the text displayed(bold, italic, underline) and I need to have an option that adds and removes timestamps from the text. To add / remove the timestamps I have to go through all the text in the textbrowser. It displays something like:

UserName: text (without timestamps)
UserName (timestamp): text (with timestamps)

BTW doesn’t work with “&lt” and “&gt”. It saves the tags but displays the tags in textbrowser (don’t need to display them, just to make them work)

Thank you in advance.

Qt 4.8.4 with MinGW
Windows 7

b1gsnak3
14th December 2012, 13:55
Solved it using a StringList for each line in the TextBrowser. For the first part of editing my text I used the StringList. When I wanted to add the new modified text I had problem when adding the html tags but I worked around it by making a custom appendFunction where I broke the string into 3 separate strings, string1, html tags and string2. I used boolean variables for each html tag and after adding the string2 I added the appropiate html end tags. Hope it helps someone someday :)