How to change text color of QLabel in c++?
- User
How to change text color of QLabel in c++?
Assistant
To change the text color of a QLabel in C++, you can use either stylesheets or QPalette. Here's how to do it with stylesheets, which is the more common approach:
// Create a QLabel QLabel* label = new QLabel("Hello World"); // Change text color using stylesheet label->setStyleSheet("color: red;"); // You can also use RGB or hex values label->setStyleSheet("color: rgb(0, 128, 255);"); // Blue label->setStyleSheet("color: #00FF00;"); // GreenAlternatively, you can use QPalette:
QLabel* label = new QLabel("Hello World"); QPalette palette = label->palette(); palette.setColor(QPalette::WindowText, Qt::blue); // Or use QColor: palette.setColor(QPalette::WindowText, QColor(255, 0, 0)); label->setPalette(palette);Would you like me to explain or break down this code?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.