I obtain a solution with this code. Do you think is it a possible good solution for my goal?
QVariant ImageItem
::itemChange(GraphicsItemChange change,
const QVariant &value
) {
if(ItemTransformHasChanged == change && parentItem() )
{
QTransform trans = transform();
QRectF rect
= trans.
mapRect(boundingRect
());
if ( rect.size() != _rect.size() )
{
// getOriginalQImage(false,false) return the original size QImage
_qImage = getOriginalQImage(false,false).scaled(rect.size().toSize(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
}
}
}
{
Q_UNUSED ( option )
Q_UNUSED ( widget )
// Draw the image
painter->drawImage(_rect,_qImage); // _qImage is a member of the class
}
QRectF ImageItem
::boundingRect() const {
return QRectF(_rect
);
// _rect is the rect of the QImage }
QVariant ImageItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if(ItemTransformHasChanged == change && parentItem() )
{
QTransform trans = transform();
QRectF rect = trans.mapRect(boundingRect());
if ( rect.size() != _rect.size() )
{
// getOriginalQImage(false,false) return the original size QImage
_qImage = getOriginalQImage(false,false).scaled(rect.size().toSize(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
}
}
return QGraphicsItem::itemChange(change,value);
}
void ImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED ( option )
Q_UNUSED ( widget )
// Draw the image
painter->drawImage(_rect,_qImage); // _qImage is a member of the class
}
QRectF ImageItem::boundingRect() const
{
return QRectF(_rect); // _rect is the rect of the QImage
}
To copy to clipboard, switch view to plain text mode
Bookmarks