Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [Moved] PyQt - Mouse events on GraphicsItems inside a GraphicsScene/GraphicsView
QtWS25 Last Chance

[Moved] PyQt - Mouse events on GraphicsItems inside a GraphicsScene/GraphicsView

Scheduled Pinned Locked Moved Language Bindings
2 Posts 1 Posters 3.8k Views
  • 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.
  • S Offline
    S Offline
    squiggly101
    wrote on last edited by
    #1

    I am trying to connect to the mouse-enter event of QGraphicsItems that are placed onto a QGraphicsScene and visualized through a QGraphicsView. From what I understand, the method to override for this is dragEnterEvent in a class derived from QGraphicsItem (or one of it's subclasses). My attempt looks like this:

    @
    class StaPoly(QtGui.QGraphicsPolygonItem):

        def __init__(self,*args):
            QtGui.QGraphicsPolygonItem.__init__(self,*args)
            self.setAcceptDrops(True)
        
        def dragEnterEvent(self,event):
            print "Enter!"        
    
    ...
    
        def draw(self):        
            p       = self.parent
    
            self.group = QtGui.QGraphicsItemGroup(scene=p.scene)
    
    ...
    
            for xpix in lons: 
                poly = QtGui.QPolygonF()
                poly << QtCore.QPointF(xpix-symw,ypix)
                poly << QtCore.QPointF(xpix,ypix+symh)                
                poly << QtCore.QPointF(xpix+symw,ypix)                
                poly << QtCore.QPointF(xpix,ypix-symh)                                                
                
                item = StaPoly(poly)
                item.setPen(QtGui.QColor(color))
                item.setBrush(QtGui.QColor(color))  
                self.group.addToGroup(item)   
    

    @

    I hope the above snippets make it clear what I am trying to do. Note that the display is generated exactly as I desire, no issue there - however the polygons that get drawn are not responding to the enter-event - I am not seeing any evidence that dragEnterEvent() is being called.

    Any advice on how to make this work?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      squiggly101
      wrote on last edited by
      #2

      The (partial) solution was this:

      @self.group.setHandlesChildEvents(False) @

      This ensures that individual items handle their own events, it seems that before the group was capturing them.

      I still have a problem in that my GraphicsView overrides the mouseMoveEvent, and when enabled, no events get propagated to scene items.

      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