|
10Qter豆
最简单的即可
我想知道item如何和代码联系 谢谢
#include "mouse.h"#include <QGraphicsScene>#include <QPainter>#include <QStyleOption>#include <math.h>#include <QKeyEvent>Mouse::Mouse(){}void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)//对老鼠进行绘制{ // Body painter->setBrush(color); painter->drawEllipse(-10, -20, 20, 40);
// Eyes painter->setBrush(Qt::white); painter->drawEllipse(-10, -17, 8, 8); painter->drawEllipse(2, -17, 8, 8);
// Nose painter->setBrush(Qt::black); painter->drawEllipse(QRectF(-2, -22, 4, 4));
// Pupils painter->drawEllipse(QRectF(-8.0 + mouseEyeDirection, -17, 4, 4)); painter->drawEllipse(QRectF(4.0 + mouseEyeDirection, -17, 4, 4));
// Ears painter->setBrush(scene()->collidingItems(this).isEmpty() ? Qt::darkYellow : Qt::red); painter->drawEllipse(-17, -12, 16, 16); painter->drawEllipse(1, -12, 16, 16);
// Tail QPainterPath path(QPointF(0, 20)); path.cubicTo(-5, 22, -5, 22, 0, 25); path.cubicTo(5, 27, 5, 32, 0, 30); path.cubicTo(-5, 32, -5, 42, 0, 35); painter->setBrush(Qt::NoBrush); painter->drawPath(path);}
|
|