void myGauge2::drawIndicator(QPainter *painter) { painter->save(); painter->translate(m_center); qreal increment=(qreal)270/100; qreal changedAngle=45+increment*m_currentValue; painter->rotate(changedAngle); QPointF topPot(0,m_colorCircleRadius+LONG1); QPointF bottomLeftPot(-m_coverBallRadius/3,0); QPointF bottomRightPot(m_coverBallRadius/3,0); painter->setPen(Qt::NoPen); QLinearGradient indicatorGradient(topPot,bottomLeftPot); indicatorGradient.setColorAt(0.0,QColor(236,187,62)); indicatorGradient.setColorAt(0.5,QColor(220,147,0)); indicatorGradient.setColorAt(1.0,QColor(236,187,62)); painter->setBrush(indicatorGradient); QVector<QPointF> potVec; potVec.push_back(topPot); potVec.push_back(bottomLeftPot); potVec.push_back(bottomRightPot); painter->drawPolygon(potVec); painter->restore(); }
void PSV_CircularIndicatorItem::drawIndicator(int zValue) { QPointF center(0, 0); QPointF topPot(center.x(), center.y() - m_colorCircleRadiusRatio * m_outerRadius/*m_coverBallRadius*/); QPointF bottomLeftPot(center.x() - m_outerRadius * m_indicatorWidthRatio, center.y()); QPointF bottomRightPot(center.x() + m_outerRadius * m_indicatorWidthRatio, center.y()); QLinearGradient indicatorGradient(topPot, bottomLeftPot); indicatorGradient.setColorAt(0.0, QColor(236, 187, 62)); indicatorGradient.setColorAt(0.5, QColor(220, 147, 0)); indicatorGradient.setColorAt(1.0, QColor(236, 187, 62)); QPolygonF polygon; polygon.append(topPot); polygon.append(bottomLeftPot); polygon.append(bottomRightPot); // if(m_polygonItem == NULL) { QGraphicsLineItem *item = new QGraphicsLineItem(this); item->setPos(m_rect.center().x(), m_rect.center().y()); item->setZValue(zValue); m_polygonItem = new QGraphicsPolygonItem(item); } m_polygonItem->setPolygon(polygon); m_polygonItem->setPen(QPen(Qt::NoPen)); m_polygonItem->setBrush(indicatorGradient); m_polygonItem->setZValue(zValue); qreal angle = (m_value - m_min) / (m_max - m_min) * 270 - 135; PSV_Public::printMes(angle,"angle"); #if QT_VERSION > QT_VERSION_CHECK(4, 6, 0) m_polygonItem->setRotation(angle); #else m_polygonItem->rotate((m_value - m_min) / (m_max - m_min) * 270 - 135); #endif }