PDA

View Full Version : setting QGraphicsItem::ItemIsMovable to False disable ContextMenu



puiseux
25th November 2014, 18:00
Hello,

all is in the title.
I have subclassed a QGraphicsPolygonItem,
- when ItemIsMovable==True, my context menu appears, as expected.
- if i disable the flag, context menu does not appear anymore.

My program is quite long and complicated, but here are the lines involved :


class NGraphicsCloisonItem(QtGui.QGraphicsPolygonItem):
Type = QtGui.QGraphicsItem.UserType + 6

def __init__(self, **dump):

[...]
super(NGraphicsCloisonItem, self).__init__(self.model.qpolygon, parent=parentitem)

[...]
self.setVisible(True)
self.setFlag(QtGui.QGraphicsItem.ItemIsMovable, False)
self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)
[...]



and in the scene :



def contextMenuEvent(self,event):
menu = someMenuThatWorksWhenMovable
for action in someListOfActions :
for view in self.views():
view.addAction(action)
menu.exec_(event.screenPos())



Thank you for your answer.