How to change text color of QLabel in c++?
- User
How to change text color of QLabel in c++?
Assistant
You can change the text color of a QLabel in C++ using several methods:
Method 1: Using setStyleSheet()
QLabel* label = new QLabel("Hello World"); label->setStyleSheet("color: red;"); // or with hex colors label->setStyleSheet("color: #FF0000;"); // or with RGB label->setStyleSheet("color: rgb(255, 0, 0);");Method 2: Using QPalette
QLabel* label = new QLabel("Hello World"); QPalette palette = label->palette(); palette.setColor(QPalette::WindowText, Qt::red); label->setPalette(palette);Method 3: Using rich text (HTML-like formatting)
QLabel* label = new QLabel(); label->setText("<font color='red'>Hello World</font>"); // or label->setText("<span style='color: blue;'>Hello World</span>");
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.