qlabel set text color
To set the text color of a QLabel in C++, you can follow these steps:
- Include the necessary header files:
#include <QLabel>
#include <QPalette>
- Create an instance of QLabel:
QLabel *label = new QLabel(this);
- Create a QPalette object:
QPalette palette;
- Set the desired text color using the QPalette object:
palette.setColor(QPalette::WindowText, Qt::red);
Here, we are setting the text color to red. You can replace Qt::red
with any other color from the available options.
- Set the palette to the QLabel:
label->setPalette(palette);
- Update the QLabel to apply the changes:
label->update();
- Set the text of the QLabel:
label->setText("Hello, World!");
By following these steps, you can set the text color of a QLabel in C++.