Naruto
Naruto

Reputation: 9634

How to get the application font color in Qt

I want to put some text on my UI.

I am drawing the text in a paint event of a widget using painter.

Here is the sample code, which shows how I am drawing the text:

QWidget::paintEvent(painter);
QPainter paint(this);
paint.drawText(QPoint(10,30),"Duplex");

However, the text color looks like the default theme color. How do I set the application font color to the text in a paint event?

Upvotes: 3

Views: 6714

Answers (2)

Naruto
Naruto

Reputation: 9634

here is the answer i got it

 QPen pen  = (QApplication::palette().text().color());

 paint.setPen(pen);

Upvotes: 13

Lohrun
Lohrun

Reputation: 6772

You have to use the QPainter::setBrush(QBrush &) and QPainter::setPen(QPen &) methods to change the color used to draw graphics (and incidently the text color).

The command paint.setPen(QPen(QColor(255,0,0)) will set the outline color to red and paint.setBrush(QBrush(QColor(0,255,0)) will set the fill color to green.

You can also use directly the QPainter::setPen(QColor &) methods to change the color of the outline.

Upvotes: 1

Related Questions