Propagating pos through mouse events and QGraphicsProxyWidget

  • (PySide 1.1, Qt 4.8)
    I'm adding a QGraphicsWidget to a QGraphicsScene. I first add several QWidgets to the scene, which return a "QGraphicsProxyWidget": I then add the proxyWidget to the layout, and finally set the layout to the QGraphicsWidget.

    QGraphicsScene -> QGraphicsWidget -> QGraphicsGridLayout -> QGraphicsProxyWidget -> QLabel

    I'm now trying to implement the "Undo": framework. In my QGraphicsScene class I override the mouseReleaseEvent:
    @def mouseReleaseEvent(self, event):
    if self.movingItem is not None and event.button() == QtCore.Qt.LeftButton:
    if self.oldPos != self.movingItem.pos(): # always fails with proxy

    However, the movingItem.pos() never changes, therefor the if statement never passes and signal never emits. This only happens when I click a widget/proxy item. If I click and drag elsewhere it returns the QGraphicsWidget, and the if statement passes.

    I've been trying to access the QGraphicsWidget from the proxy but that doesn't seem possible. Anyone worked around this? Suggestions?

    I'm now trying to hack the mousePressEvent and mouseMoveEvent to ignore the proxy and target the graphicswidget.

  • Ugly hack in mousePressEvent, ignoring QGraphicsProxyWidgets and mapping mousePos to 'any' QGraphicsWidget it intercepts. Of course this makes the assumption that the first graphicswidget that contains the point is the correct one and gets pushed to the undo stack.

    if isinstance(self.movingItem,QtGui.QGraphicsProxyWidget):
    for item in self.items():

                if isinstance(item,QtGui.QGraphicsProxyWidget):
                if isinstance(item,QtGui.QGraphicsWidget):
                    if item.contains(item.mapFromScene(mousePos)):
                        self.movingItem = item

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.