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. HTML String Question
Forum Updated to NodeBB v4.3 + New Features

HTML String Question

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.4k Views 2 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.
  • D Offline
    D Offline
    deleted28
    wrote on last edited by deleted28
    #1

    Hello,

    i have 2 variants of a HTML String:

            QString tmpStr_tx = QString("<font color = \"red\"> %1 %2</font>").arg("ECW<< ").arg(ba2OutString(currMessage_tx));
            ui->lvWidget->appendHtml(tmpStr_tx);
    
            QString tmpStr_tx = QString("<font color = \"red\"> %1 %2</font>").arg("<<ECW ").arg(ba2OutString(currMessage_tx));
            ui->lvWidget->appendHtml(tmpStr_tx);
    

    In lvWidget (QPlainTextEdit) only the part until occurence of "<<" is displayed.
    1st: ECW and nothing else
    2nd empty line with linefeed

    Problem seem sto be the 2 '<' in arg %1

    How to form the html string to display "<<ECW " ?

    Maybe something using "htmlspecialchars" but i do not know how to.
    '<' (less than) becomes "&lt"
    '>' (greater than) becomes "&gt"

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      < and > are special characters in html so yes, you should use entities to display them. Second thing is - if you're passing a string literal as an argument why not embed it in the string in the first place?

      QString tmpStr_tx = QString("<font color = \"red\"> ECW&lt;&lt; %1</font>").arg(ba2OutString(currMessage_tx));
      ui->lvWidget->appendHtml(tmpStr_tx);
      
      1 Reply Last reply
      0
      • D Offline
        D Offline
        deleted28
        wrote on last edited by deleted28
        #3
        why not embed it in the string ...
        

        because text of arg1 is dependend on arg2.
        The literal is for testing now, but will be replaced by a QStringvariable
        generated above this line in next version.

        Thanks for the answer, hopefullyit will work in .arg( .... ) also.
        Yup:

            QString tmpStr_tx = QString("<font color = \"red\"> %1 %2</font>").arg("&lt;&lt;ECW ").arg(ba2OutString(currMessage_tx));
        
        Chris KawaC 1 Reply Last reply
        0
        • D deleted28
          why not embed it in the string ...
          

          because text of arg1 is dependend on arg2.
          The literal is for testing now, but will be replaced by a QStringvariable
          generated above this line in next version.

          Thanks for the answer, hopefullyit will work in .arg( .... ) also.
          Yup:

              QString tmpStr_tx = QString("<font color = \"red\"> %1 %2</font>").arg("&lt;&lt;ECW ").arg(ba2OutString(currMessage_tx));
          
          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @wally123 said:

          hopefullyit will work in .arg( .... ) also.

          It will. It's just constructing a string. The html parsing happens later, when you pass that string to appendHtml().

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted28
            wrote on last edited by deleted28
            #5

            I need colored text for better reading and analyzing a protocol coming in as a lot of currMessages.
            Any alternative suggestions to display colored text in QPlainTextEdit ?
            I used the first possibility i found :)

            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