Qt - QPainter.DrawText doesnt draw the text
13,095
setting the pen-style over
painter.setPen(colorStyle);
solved the problem. thanks to Mat
Author by
Postback
Updated on June 29, 2022Comments
-
Postback almost 2 years
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, exceptdrawText
would not use thesetBrush()
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