2

I'm creating an analog clock in Qt-Creator 5, now I want to draw the numbers to the screen, but it doesn't work?

painter.drawText(QPoint(50, 50), "12");

I absolutely don't see the point why it doesn't work. when I replace this line in my code with a .drawEllipse, it works fine. So the position/color can't be the problem, except drawText would not use the setBrush() color.

Anyone knows how to correctly draw text on the screen with the QPainter?

//previous code only draws blue ellipses with white background
QColor secondColor(240,0,0);

painter.setPen(Qt::NoPen);
painter.setBrush(secondColor);
painter.save();

QFont font=painter.font() ;
font.setPointSize(18);
painter.setFont(font);
painter.drawText(QPoint(50, 50), "12");

because it's at the end of paintEvent it can't be overdrawn

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
Postback
  • 619
  • 2
  • 9
  • 27
  • 2
    Could be your pen color. Could be you're painting something on top. There's really no way of knowing where your bug is without a piece of code that reproduces your problem. – Mat May 07 '13 at 06:06
  • i've added some code, but its at the end of paintEvent, so overdrawing cant be the problem. color is Red, also no problem because everything other is white – Postback May 07 '13 at 06:09
  • 3
    `painter.setPen(Qt::NoPen);`? – Mat May 07 '13 at 06:11
  • i guess in the analog-clock-tutorial from QT the pen always got setted to `Qt::NoPen` and in no drawText code snippet i saw a `setPen`. checked it now by setting it to red and worked. thx – Postback May 07 '13 at 06:15

1 Answers1

5

setting the pen-style over

 painter.setPen(colorStyle);

solved the problem. thanks to Mat

Postback
  • 619
  • 2
  • 9
  • 27