Mouse event is not working for "pyqtgraph.graphicsItems.TextItem" and "pyqtgraph.graphicsItems.ArrowItem"

706 views
Skip to first unread message

Rakesh Mishra

unread,
Mar 28, 2014, 1:39:30 AM3/28/14
to pyqt...@googlegroups.com
Hi Luke,

I want to use Mouse events for TextItem and ArrowItem. but it's not working for me could  you please help me figure out the  problem, here is my Code

class MyTextItem(TextItem):
    def __init__(self, text='', color=(200,200,200), html=None, anchor=(0,0), border=None, fill=None, angle=0):
        TextItem.__init__(self, text, color, html, anchor, border, fill, angle)
       
    def mousePressEvent(self, *args, **kwargs):
        print "mouse has pressed"
        return TextItem.mousePressEvent(self, *args, **kwargs)
  
    def mouseDragEvent(self, ev):
        print "Drag Event"
  

class MyArrow(ArrowItem):
    def __init__(self, **opts):
        ArrowItem.__init__(self,**opts)
        self.setZValue(-1)
    def mousePressEvent(self, *args, **kwargs):
        print " mouse clicked "
        return ArrowItem.mousePressEvent(self, *args, **kwargs)
    def mouseMoveEvent(self, *args, **kwargs):
        print "mouse is moving"
        return ArrowItem.mouseMoveEvent(self, *args, **kwargs)

Thanks
Rakesh
  

Luke Campagnola

unread,
Apr 1, 2014, 9:17:09 AM4/1/14
to pyqt...@googlegroups.com
On Fri, Mar 28, 2014 at 1:39 AM, Rakesh Mishra <mishra.r...@gmail.com> wrote:
I want to use Mouse events for TextItem and ArrowItem. but it's not working for me could  you please help me figure out the  problem

 Thanks, Rakesh. I can confirm this is a bug. Will reply here when a fix is pushed.

ivan....@gmail.com

unread,
Aug 4, 2016, 9:52:25 AM8/4/16
to pyqtgraph
I'm trying to do the same thing. Luke, could you please explain why it doesn't work and what the bug is?
 
Message has been deleted

vas...@gmail.com

unread,
Aug 4, 2016, 4:59:02 PM8/4/16
to pyqt...@googlegroups.com

On Thu, Aug 4, 2016 at 3:52 PM, <ivan....@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/4168644f-beb7-413b-b58f-3be9b3be69d9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ivan....@gmail.com

unread,
Aug 5, 2016, 9:56:17 AM8/5/16
to pyqtgraph
Thanks, Vasilije. That link gave me most of the information I needed.

To implement, I added a pg.SignalProxy to my plot with the signal, self.plot.scene().sigMouseClicked and the slot self.mouseClicked.
In my __init__ method of the class:
    self.window = pg.GraphicsWindow(...)
    self.plot = self.window.addPlot(...)
    self.proxyMouse = pg.SignalProxy(self.plot.scene().sigMouseClicked, slot=self.mouseClicked)

The in my mouseClicked method:
def mouseClicked(self, ev):
    if ev[0].button() != 1: return
    pos = ev[0].scenePos()
    items = self.window.scene().items(pos, QtCore.Qt.IntersectsItemBoundingRect, QtCore.DescendingOrder)
    if isinstance(items[0], QGraphicsTextItem):
        widget = items[0].parentItem()

widget is now the TextItem that was clicked on. Note that the default ItemSelectionMode does not catch the object.

--
Ivan
Reply all
Reply to author
Forward
0 new messages