PDA

View Full Version : problem resizing rect



dreamer
5th May 2008, 18:02
I write the code for resizing a QRectItem and it works very well.
For example, to resize my custom QrectItem from the top-right corner, i calculate the new rect in this manner:


QRectF new_rect(QPointF(rect().bottomLeft().x(),event->pos().y()),
QPointF(event->pos().x(),boundingRect().bottomLeft().y()));


When I use the "same" approach for resizing my custom QPixmapItem, it give me problem and resize doesn't work!!



QRect new_rect(QPoint(pixmap().rect().bottomLeft().x(),
event->pos().toPoint().y()),
QPoint(event->pos().toPoint().x(),
pixmap().rect().bottomLeft().y()));


What's wrong???

dreamer
6th May 2008, 11:09
Have someone any idea, dealing with the resizing of a QGraphicsPixmapItem???

Reading the documentation i find many reasons that could introduce problem during the resize:
1)When we resize a QGraphicsRectItem, we work on a QrectF that is more accurate to give us the corners coordinate(QGraphicsPixmapItem work with QRect Object)
2)QGraphicsPixmapItem objects, start drawing its pixmap, starting from the QpointF "offset()", which defines the top-left corner of the pixmap; so i think that if we change the rect of the pixmap, we have to change also the offset() of the current resizing item.

I make a lot of different version of resizing, but i can't find the solution.
I find the right resizing method for the bottom side and the bottom right corner(So i think the problem starts when we modify the top-left corner!!!)

Bottom-side:


QRect new_rect(pixmap().rect().topLeft(),
QPoint(pixmap().rect().topRight().x(),event->pos().toPoint().y()));
setPixmap(QPixmap::fromImage(image.scaled(QSize(ne w_rect.width(),new_rect.height()),Qt::IgnoreAspect Ratio,Qt::FastTransformation)));


Botto-right corner:


QRect new_rect(pixmap().rect().topLeft(),QPoint(event->pos().toPoint().x(),
event->pos().toPoint().y()));
setPixmap(QPixmap::fromImage(image.scaled(QSize(ne w_rect.width(),new_rect.height()),Qt::IgnoreAspect Ratio,Qt::FastTransformation)));


I hope someone will help me.........thanks a lot.