Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    HTML String Question

    General and Desktop
    2
    5
    1095
    Loading More Posts
    • 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
      deleted28 last edited by deleted28

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by Chris Kawa

        < 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 Reply Quote 0
        • D
          deleted28 last edited by 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 Kawa 1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators @deleted28 last edited by

            @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 Reply Quote 0
            • D
              deleted28 last edited by deleted28

              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 Reply Quote 0
              • First post
                Last post