The image basically turns into a lump of solid mass on continuous resizing( expanding/decreaing width or height).
This is normal. What you need to do is change the method for the effect you desire. Rather than constantly changing the same image, start with a source image of the maximum size you expect the user will require. This image will not be altered.
In the mouseMove function, update member variables to store the size of the image that you display.
Then, in the PersonSizeGraphicsItem's paint function, use drawImage to specify the source image and the target rect to draw the image at the size that was updated in mouseMoveEvent:-
void QPainter::drawImage(const QRectF & rectangle, const QImage & image);
So, by keeping the source image at its original size, you won't be distorting it more and more with each successive resize.
class PersonSizeGraphicsItem : public QGraphicsItem
{
public:
PersonSizeGraphicsItem(QGraphicsItem* parent);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0)
private:
QRectF m_imageRect;
QImage m_image;
};
void PersonSizeGraphicsItem::mouseMoveEvent()
{
// Update the image rect here
}
void PersonSizeGraphicsItem::paint(QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->drawImage(m_imageRect, m_image);
}