HTML String Question



  • 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"


  • Moderators

    < 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);
    


  • 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));
    

  • Moderators

    @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().



  • 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 :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.