How to draw "Draw Arc Ticks".
-
void wCtrl_Indicator::paintEvent(QPaintEvent* e) { QPainter painter(this); drawBackGround(&painter); drawTicks(&painter); } void wCtrl_Indicator::drawTicks(QPainter* painter) { QRect drawingRect(this->rect()); //drawingRect.adjusted(15, 15, -20, -20); QBrush brushActive(Qt::red); QPen pen(QBrush(brushActive), 2); pen.setCapStyle(Qt::FlatCap); painter->setPen(pen); painter->setBrush(brushActive); painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); qreal dStartAngle = 225; qreal dEndAngle = -45; painter->rotate(-dStartAngle); qreal dAngleStep = (-dEndAngle + dStartAngle) / m_nStep; for (int i = 0; i < m_nStep; i++) { //painter->drawLine((drawingRect.center().x(), drawingRect.center().y()); painter->drawLine(30, 0, 40, 0); painter->rotate(dAngleStep); } } void wCtrl_Indicator::drawBackGround(QPainter* painter) { QRect drawingRect(0, 0, this->size().height(), this->size().height()); QBrush brushBackgnd(QColor(63, 67, 70)); QPen pen(QBrush(brushBackgnd), 10); pen.setCapStyle(Qt::FlatCap); painter->setPen(pen); painter->setBrush(brushBackgnd); painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); painter->drawArc(drawingRect.adjusted(15, 15, -20, -20), 90 * 16, ConvertAngle(m_nMax) * 16); }
I want to draw Tick, how can I approach it? -
QPoint c=rect().center(); painter.translate(c); painter.rotate(-225); float step=20; for(int s=0;s<=step;s++) { painter.drawLine(30,0,40,0); painter.rotate(270/step); } float val=50; float maxVal=100; // range 0-100 painter.resetTransform(); painter.translate(c); painter.rotate(-225); painter.rotate(270*val/maxVal); painter.drawLine(00,0,40,0);
[EDIT] better code and adding current value position
-
-
@IknowQT said in How to draw "Draw Arc Ticks".:
When drawing an oval progress, it seems to be a problem due to increasing the pen thickness and changing the drawing right (adjusted), but can you automatically adjust the center even if the thickness is increased?
Sorry I don't understand what you want to do.
-
I'm not good at English, so please understand
I want to move the ellipse to the center
============================================
Add
The move to the center was successful, but why is the ellipse cut off to the sides?void wCtrl_Indicator::drawBackGround(QPainter* painter) { //QRect drawingRect(this->rect()); QPoint p = this->rect().center(); QRect drawingRect(1, 1, this->size().width(), this->size().height()); QBrush brushBackgnd(QColor(63, 67, 70)); QPen pen(QBrush(brushBackgnd), 10); pen.setCapStyle(Qt::FlatCap); painter->setPen(pen); painter->setBrush(brushBackgnd); painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); painter->drawArc(drawingRect, 90 * 16, ConvertAngle(m_nMax) * 16); /*painter->drawArc(drawingRect.center().x(), drawingRect.center().y(), this->size().width(), this->size().height(), 90 * 16, ConvertAngle(m_nMax) * 16);*/ }
I think there's a problem with drawing right.
-
-
This is not what I want, but the circle is in the center=================================
addOut of the many, do you recommend 20 as the rect argument? At 20, you get the center, but if you put another number, you lose the center again.