Hello,
I have following custom shape
#include "basicshape.h"
{
setFlags(ItemIsSelectable|ItemIsMovable|ItemSendsGeometryChanges);
}
QRectF BasicShape
::boundingRect() const {
return brect;
}
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->save();
painter->drawRect(brect);
painter->restore();
}
void BasicShape
::setRect(QRectF rct
) {
prepareGeometryChange();
brect = rct;
update();
}
#include "basicshape.h"
BasicShape::BasicShape(QGraphicsItem *parent) :
QGraphicsItem(parent),brect(100,100,200,50)
{
setFlags(ItemIsSelectable|ItemIsMovable|ItemSendsGeometryChanges);
}
QRectF BasicShape::boundingRect() const
{
return brect;
}
void BasicShape::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->save();
painter->drawRect(brect);
painter->restore();
}
void BasicShape::setRect(QRectF rct)
{
prepareGeometryChange();
brect = rct;
update();
}
To copy to clipboard, switch view to plain text mode
And this object is passed in other object which attaches handles as shown in attachment to this shape and also makes this shape a parent item to that handle item. Now when I move handles by pressing it resizes correctly. But when I move bottom center point above top center or right center point toward left than left center then shape distorts. This is because moving handle position becomes negative. And due to this negative point it is unable to update bounding rect properly.
Is there any remedy where this issue will be addressed. This becomes worst when shape is instead of rectangle it is line item.
Manish
Bookmarks