I'm trying to make the qgraphicsitem not moveable. I tried setting the flag when its being clicked and tried setting it when the item is created etc. I can call flags(); and it shows that ItemIsMovable is not in the flags list yet it is still able to be moved. I have noticed when I pop up a modeless dialog in my mainwindow.cpp then go back to the mainwindow without closing the dialog and try to move an item it then recognizes the flag and I can't move the item until I close the dialog. I'm not sure why qgraphicsscene is ignoring the flag. Can anyone please explain how I can get this to work?
Here is some of my code stripped down to the relevant stuff.
//GraphScene.h
{
private:
protected:
};
//GraphScene.cpp
{
x = qgraphicsitem_cast<QGraphicsItem*>(itemAt(event->scenePos(), QTransform()));
if (x)
{
}
}
//y.h
class y : public QGraphicsObject
{
protected:
};
//y.cpp
y::y()
{
setFlags(ItemIsSelectable | ItemIsFocusable);
setAcceptHoverEvents(true);
}
{
update();
}
//GraphScene.h
class GraphScene : public QGraphicsScene
{
private:
QGraphicsItem* x;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
//GraphScene.cpp
void GraphScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
x = qgraphicsitem_cast<QGraphicsItem*>(itemAt(event->scenePos(), QTransform()));
if (x)
{
x->setFlag(QGraphicsItem::ItemIsMovable,false);
}
QGraphicsScene::mousePressEvent(event);
}
//y.h
class y : public QGraphicsObject
{
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
};
//y.cpp
y::y()
{
setFlags(ItemIsSelectable | ItemIsFocusable);
this->setFlag(QGraphicsItem::ItemIsMovable,false);
setAcceptHoverEvents(true);
}
void y::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks