PDA

View Full Version : resize a QGraphicsRectItem



gbmtoday
14th January 2010, 22:41
Hi there

I have QGraphicsRectItem and I want to resize it , but I can't.

I tried this , but it doesnt work



QRectF rect ( player->shape()->pos().x() ,
(player->shape()->pos().y()+WINDOW_END_H)/2.0,
PLAYER_WIDTH_P,
PLAYER_HEIGHT_P/2.0);

player->shape()->setRect(rect);


player->shape() returns a QGraphicsRectItem *

I just want to change the hight of the rect to a half .

I tried this , too


player->shape()->rect().setHeight(player->shape()->rect().height() / 2.0 );


It doesnt work too .

Do you know what is the problem?

gbmtoday
15th January 2010, 16:39
hey please somebody answer my question :(

kichi
15th January 2010, 19:11
QGraphicsRectItem::shape() returns copy of the QPainterPath object.
This method is to get the shape.

If you want resize the rect, you can use QGraphicsRectItem::setRect() instead.

or, you can override the QGraphicsRectItem::shape(), and return new shape.

kichi
15th January 2010, 19:16
or, You can override the QGraphicsRectItem::boundingRect() too.

blooglet
10th February 2011, 16:12
QGraphicsRectItem::setRect() did it for me. Thanks!