I have made a custom class derived from QGraphicsRectItem.
class CornerPoint : public QGraphicsRectItem
{
public:
CornerPoint(QPointF centre);
enum { Type = UserType + 1 };
int type() const{ return Type; }
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
public slots:
void updatePosition(QPointF);
};
CPP File
CornerPoint::CornerPoint(QPointF centre): QGraphicsRectItem(NULL)
{
setPos(55,22);
setRect(0,0,99,99);
}
QVariant CornerPoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
std::cout << "Change is" << change << std::endl;
if( QGraphicsItem::ItemPositionChange == change && scene())
{
std::cout << "New values " << value.toPointF().x() << value.toPointF().y() << std::endl;
}
return QGraphicsItem::itemChange(change, value);
}
I have made these objects selectable and moveable. But when I drag them, I dont receive the signal for position change of this rectangle. All I receive are the signals with value 4 (ItemSelectedChange
) and 14 (ItemSelectedHasChanged
).
This post says that I need to enable some flags. But I can't find any example of any one doing this, and using these flags is giving errors.
Crap.
I just had to enable this flag :
setFlag(GraphicsItemFlag::ItemSendsGeometryChanges);