views:

194

answers:

2

Hi,

I want to put some text on my UI, I am drawing the text in 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");

but, the text color is looks like the default theme color, how to set the application font color to the text in paint event..

Thanks

A: 

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.

Lohrun
Thanks, lohrun..infact i wanted how to take the default text color.. i got the answer too.. i will place it
Shadow
+2  A: 

here is the answer i got it

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

 paint.setPen(pen);
Shadow