Hello. Faced with such a problem, there is an overridden method :: paint (QPainter * painter)

In it, I draw a circle, and I need to place a line in the center, which is time. Krull can be reshaped in size. But how to make it so that the string changes its size over time? Below is the code

//Draw object QBrush brushNonActiveFull(nonActiveColorFull_); QBrush brushHours(borderHoursColor_); painter->setPen(Qt::NoPen); painter->setRenderHints(QPainter::Antialiasing, true); /////////Circle/////// QRectF outerRect1(boundingRect().adjusted(0,0,0,0)); QRectF innerRect1(boundingRect().adjusted(8,8,-8,-8)); QPainterPath path1; path1.moveTo(outerRect1.center().x(), 0); path1.arcTo(outerRect1, 90, 360); path1.arcTo(innerRect1, 90, 360); path1.closeSubpath(); painter->fillPath(path1, brushNonActiveFull); QPainterPath path2; path2.moveTo(outerRect1.center().x(), 0); path2.arcTo(outerRect1, 90, angleOfRotationFull_); path2.arcTo(innerRect1, 90 + angleOfRotationFull_, -angleOfRotationFull_); path2.closeSubpath(); painter->fillPath(path2, brushHours); /////////Time/////// QPainterPath path5; QPoint point(70, 140); auto time = QTime::currentTime(); QFont outline_font(QLatin1String("times"), 14); QFontMetrics fm(outline_font); path5.addText(point, outline_font, time); painter->fillPath(path5, brushMinutes); 

Thanks in advance to everyone.

  • In the QFont string outline_font (QLatin1String ("times"), 14); value 14 to change depending on changes in the radius of the circle. Another way is to change the value of QFont :: setPixelSize . We must experiment - Alexander Chernin
  • And how to properly center? This is paramount to me now. - Alexey Ananyev 4:16 pm

0