Question

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

Was it helpful?

Solution

setting the pen-style over

 painter.setPen(colorStyle);

solved the problem. thanks to Mat

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top