Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Propagating pos through mouse events and QGraphicsProxyWidget

Propagating pos through mouse events and QGraphicsProxyWidget

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 913 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BreakBad
    wrote on last edited by
    #1

    (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":http://qt-project.org/doc/qt-4.8/qgraphicsproxywidget.html. 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":http://qt-project.org/doc/qt-4.8/tools-undoframework.html 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
    self.itemMoved.emit(self.movingItem,self.oldPos)
    super(DiagramScene,self).mouseReleaseEvent(event)@

    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.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BreakBad
      wrote on last edited by
      #2

      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):
                      continue
                  
                  if isinstance(item,QtGui.QGraphicsWidget):
                      if item.contains(item.mapFromScene(mousePos)):
                          self.movingItem = item
                          break@
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved