TextEdit Colored Texts or StatusBar Colored Texts
Solved
General and Desktop
-
Hi, I have the following code to display Red, Green, Blue of a particular pixel in an image.
ui->textEdit->append(QString("RED = %1, GREEN = %2, BLUE = %3").arg(rgb.red()).arg(rgb.green()).arg(rgb.blue()));
However, the text that came out is a bit ugly.
How can I set the color? I want to display in TextEdit that I have or the StatusBar of my mainwindow.
Edit: I want it to be something like this
-
@Stevendragoes Hi,
You can use html:
QString("<font color=\"#FF0000\">RED = %1</font>, <font color=\"#00FF00\">GREEN = %2</font>, <font color=\"#0000FF\">BLUE = %3</font>").arg(rgb.red()).arg(rgb.green()).arg(rgb.blue());
-
QColor rgb; ui->textEdit->append(QString("<font color=\"red\">RED, </font>" "<font color=\"green\">GREEN, </font>" "<font color=\"blue\">BLUE </font>")); ui->textEdit->append(QString("<font color=%1>RED, </font>" "<font color=%2>GREEN, </font>" "<font color=%3>BLUE </font>") .arg(rgb.fromRgb(255,0,0).name()) .arg(rgb.fromRgb(0,255,0).name()) .arg(rgb.fromRgb(0,0,255).name())); ui->textEdit->append(QString("<font color=%1>RED, </font>" "<font color=%2>GREEN, </font>" "<font color=%3>BLUE </font>") .arg("#ff0000") .arg("#00ff00") .arg("#0000ff"));