源码地址,使劲戳我!
先放效果图
绘制关键代码
void Flower::paint(QPainter* painter,const QStyleOptionGraphicsItem* style,QWidget* widget) {
painter->setRenderHint(QPainter::Antialiasing,true);
//200X200
m_scale = m_rect.width() / 200.0;
//画头
QPainterPath headPath;
headPath.addEllipse(-m_scale * 60,-m_scale * 60,2 * 60 * m_scale,2 * 60 * m_scale);
painter->setPen(QPen(Qt::NoPen));
painter->setBrush(QBrush(Qt::yellow));
painter->drawPath(headPath);
m_leftEyePos.setX(-15 * m_scale);
m_leftEyePos.setY(-15 * m_scale);
m_rightEyePos.setX(15 * m_scale);
m_rightEyePos.setY(-15 * m_scale);
m_eyeWidth = m_eyeHeight = 5 * m_scale;
painter->setBrush(QBrush(Qt::black));
painter->drawEllipse(m_leftEyePos,m_eyeWidth,m_eye