Results 1 to 2 of 2

Thread: Saving html tags in QString and displaying them correctly in a QTextBrowser

  1. #1
    Join Date
    Dec 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Saving html tags in QString and displaying them correctly in a QTextBrowser

    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

  2. #2
    Join Date
    Dec 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving html tags in QString and displaying them correctly in a QTextBrowser

    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

Similar Threads

  1. Replies: 1
    Last Post: 18th January 2011, 12:48
  2. Replies: 1
    Last Post: 2nd January 2011, 10:54
  3. Matching HTML tags
    By pucara_faa in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2010, 13:19
  4. Html tags in QTreeView
    By 1111 in forum Qt Programming
    Replies: 1
    Last Post: 13th March 2009, 01:41
  5. QTextBrowser, add support for custom tags
    By qtcos in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2007, 16:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.