There's a better way. In your item, reimplement the itemChange() virtual function. Handle the ItemPositionChange case to fixate one of your axises. You can keep QGraphicsItem's default move implementation, and still only allow moving along one axis.
{
if (change == ItemPositionChange)
return QPointF(pos
().
x(), value.
toPointF().
y());
}
QVariant MyItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange)
return QPointF(pos().x(), value.toPointF().y());
return QGraphicsItem::ItemChange(change, value);
}
To copy to clipboard, switch view to plain text mode
Neat? ;-)
Bookmarks