Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Displaying HTML codes in QLabel
QtWS25 Last Chance

Displaying HTML codes in QLabel

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 2 Posters 18.8k Views
  • 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.
  • A Offline
    A Offline
    AS.Sri
    wrote on last edited by
    #1

    Hello All,

    I am getting html codes embedded in the xml from the server for example:
    @"Robert Glück ; drawings by Edward Aulerich"@ where ü is getting displayed as &<no space>#252; and when i set it to the QLabel the html code doesn't get encoded. Is there a way by which i can display it correctly?

    Thanks,

    Sri

    PS: i gave <no space> coz the text edit is converting it to ü Please remove <no space> to get he exact code.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You can try to wrap it in a pair of <html></html> tags or force QLabel to interpret the text as HTML by using QLabel::setTextFormat(Qt::RichText)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AS.Sri
        wrote on last edited by
        #3

        Hi Andre,

        Thanks a lot for the help. I have one more problem where i have to display the same text on a QListWidget but according to doc RichText can be applied only to widgets which support RichText. So, i did the following:
        @QStaticText text;
        text.setTextFormat(Qt::RichText);
        text.setText("ü");@

        And set the same to QListWidgetItem but, i realized that QListWidgetItem doens't support RichText. Do i have create a QLabel and place it as QListWidgetItem using setWidgetItem or is there any another workaround?

        Thanks,

        Sri

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          QListViews by default do not support rich text, but they do support unicode. That means that you can display the whole character set, including unlauts, ringel-S, and basically anything else you can come up with. I am not sure if there is Qt API to convert HTML escape sequences to unicode for a text, but if not, it would not be hard to make yourself.

          I would not go mucking about with putting labels on an item view just for this.

          Edit: perhaps you can abuse QTextDocument for the translation from HTML to unicode.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AS.Sri
            wrote on last edited by
            #5

            Hello Andre,

            Thanks once again and i did the following:
            @QPointer<QTextDocument> doc = new QTextDocument();
            doc->setHtml(mBookDetail->authorsList.at(index));
            QListWidgetItem* item = new QListWidgetItem(doc->toPlainText());
            mAuthorsList->insertItem(index,item );
            delete doc;@

            I will take up writing an API to convert HTML escape sequences to unicode for a text.

            I have one Request, Shouldn't there be a sub-category in the forum which should be something like "Qt General" because my doubt was on Qt irrespective of which platform i am working on.

            Thanks,

            Sri

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              I would not create/destroy the QTextDocument for each item, but otherwise, I'm glad it works. Just convert the text once (on loading, for example) using the same QTextDocument instance. Also, using a QPointer is not really needed here.

              The forum structure request is better put in the Beta Testing forum, or better yet, on Jira.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AS.Sri
                wrote on last edited by
                #7

                Thanks for the advice. Also, i have the raised the question in Beta Testing Forum.

                Thanks,

                Sri

                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