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
On Thursday, August 4, 2016 at 4:59:02 PM UTC-4, Vasilije VaskeVanja wrote:
>
> To try with something like
> http://stackoverflow.com/questions/27222016/pyqt-mousepressevent-get-object-that-was-clicked-on
> ?
>
> Good luck,
> Vasilije
>
>
>
> On Thu, Aug 4, 2016 at 3:52 PM, <[email protected] <javascript:>> wrote:
>
>>
>>
>> On Friday, March 28, 2014 at 1:39:30 AM UTC-4, Rakesh Mishra wrote:
>>>
>>> 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 Codeclass
>>> 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)ThanksRakesh *
>>>
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/7c697bba-fdb4-4eeb-9910-75aa3b3f403b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.