I solved it.
Here is the working code:
for( int j = 0; j < readBytes; j++)
{
if( partOfText[j] == 'A' )
{
combineHtml.
append( QString( "<span style = 'color: red'>") }
else
{
combineHtml.
append( QString( "<span style = 'color: blue'>") }
}
combineHtml.append( "</p>");
std::cout << combineHtml.toStdString();
objQPlainTextEdit.appendHtml( combineHtml );
QString combineHtml = "<p>";
for( int j = 0; j < readBytes; j++)
{
if( partOfText[j] == 'A' )
{
combineHtml.append( QString( "<span style = 'color: red'>")
+ QString( partOfText[j]) + QString( "</span>"));
}
else
{
combineHtml.append( QString( "<span style = 'color: blue'>")
+ QString( partOfText[j]) + QString( "</span>"));
}
}
combineHtml.append( "</p>");
std::cout << combineHtml.toStdString();
objQPlainTextEdit.appendHtml( combineHtml );
To copy to clipboard, switch view to plain text mode
Here partOfText is QString, and objQPlainTextEdit is an object of QPlainTextEdit.
Output generated by the above code is as follows:
<p><span style = 'color: blue'>C</span><span style = 'color: red'>A</span><span style = 'color: red'>A</span><span style = 'color: blue'>T</span><span style = 'color: blue'>C</span><span style = 'color: blue'>T</span><span style = 'color: blue'>C</span><span style = 'color: blue'>C</span><span style = 'color: red'>A</span><span style = 'color: blue'>T</span></p>]
<p><span style = 'color: blue'>C</span><span style = 'color: red'>A</span><span style = 'color: red'>A</span><span style = 'color: blue'>T</span><span style = 'color: blue'>C</span><span style = 'color: blue'>T</span><span style = 'color: blue'>C</span><span style = 'color: blue'>C</span><span style = 'color: red'>A</span><span style = 'color: blue'>T</span></p>]
To copy to clipboard, switch view to plain text mode
11.png
Bookmarks