• 9291阅读
  • 2回复

如何理解qt4例子collidingmice中QGraphicsItem的boundingRect [复制链接]

上一主题 下一主题
离线g0ose
 

只看楼主 倒序阅读 楼主  发表于: 2008-11-21
如何理解qt4例子collidingmice中QGraphicsItem的boundingRect
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
QRectF Mouse::boundingRect() const
{
    qreal adjust = 0.5;
    return QRectF(-20 - adjust, -22 - adjust,  40 + adjust, 83 + adjust); //就是这里如何理解???
}

QPainterPath Mouse::shape() const
{
    QPainterPath path;
    path.addRect(-10, -20, 20, 40);
    return path;
}

void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    qreal x = 0;
    qreal y = 0;
    qreal MX = 450;
    qreal MY = 450;

    painter->drawLine(x, MY * -1, x ,  MY );
    painter->drawLine(-1 * MX, y, MX ,  y );

    // 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);
}
离线g0ose

只看该作者 1楼 发表于: 2008-11-24
。。。。。。。。。。。。。。。。。
离线marslee_suc
只看该作者 2楼 发表于: 2008-11-25
:boundingRect() 我理解这个是ITEM的边界。
快速回复
限100 字节
 
上一个 下一个