qlabel set text color

To set the text color of a QLabel in C++, you can follow these steps:

  1. Include the necessary header files:
#include <QLabel>
#include <QPalette>
  1. Create an instance of QLabel:
QLabel *label = new QLabel(this);
  1. Create a QPalette object:
QPalette palette;
  1. 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.

  1. Set the palette to the QLabel:
label->setPalette(palette);
  1. Update the QLabel to apply the changes:
label->update();
  1. 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++.