Results 1 to 1 of 1

Thread: GraphicsItemChange and QTransform

  1. #1

    Default GraphicsItemChange and QTransform

    i want to limit QGraphicsItem object move only inside in QGraphicsScene's sceneRect, i rewrite QGraphicsItem::itemChange function below like Qt assistant shows,

    QVariant Rectangle::itemChange( GraphicsItemChange change, const QVariant &value )
    {
    if ( change == ItemPositionChange && scene() )
    {
    QPointF newPos = value.toPointF();
    QRectF rect = scene()->sceneRect();
    QRectF sbRect = sceneBoundingRect();
    if ( !rect.contains( newPos ) )
    {
    qreal x = qMin( rect.right() - boundingRect().width(), qMax( sbRect.left(), rect.left() ) );
    newPos.setX( x - boundingRect().x() );

    qreal y = qMin( rect.bottom() - boundingRect().height(), qMax( sbRect.top(), rect.top() ) );
    newPos.setY( y - boundingRect().y() );

    return newPos;
    }
    }
    return QGraphicsItem::itemChange( change, value );
    }

    and it works right,but when i rotate the item,
    QPointF center = mouse->boundingRect().center();
    mouse->setTransform( QTransform().translate( center.x(), center.y() ).rotate( 90 ).translate( -center.x(), -center.y() ), true );

    it doesn't work! what is the reason?
    Attached Files Attached Files

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.