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. [SOLVED]Saving html tags in QString and displaying them correctly in a QTextBrowser
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Saving html tags in QString and displaying them correctly in a QTextBrowser

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views 1 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.
  • B Offline
    B Offline
    b1gsnak3
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • U Offline
      U Offline
      ultim8
      wrote on last edited by
      #2

      QTextBrowser only supports a "subset of the HTML standard":http://qt-project.org/doc/qt-4.8/richtext-html-subset.html. Calling toHtml(), it's going to do it's best to convert your document into the HTML it supports. If that document didn't originate from a call to setHtml(), there is no promise that the layout is going to be spot on. Actually, you can pretty much bet that it won't be.

      But you can do all this through the QTextDocument directly. You can insert new text fragments or edit existing fragments (for bolding/underlining/etc) with QTextCursor.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        b1gsnak3
        wrote on last edited by
        #3

        @Jason.Dolan I know this. I used this already when first entered the html tags in the QTextBrowser. The only problem is that I need to rework the TextBrowser text so that I can insert some strings into it. For example, in yahoo, when you enable or disable the timestamps. I want to add the timestamps in between the username and text portions of text.

        Anyway... Managed it by adding a QStringList for every line in which I saved the strings with tags, and then added them to the TextBrowser.

        Don't know if it's the best idea though :)

        1 Reply Last reply
        0

        • Login

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