Print PlotCurveItem name on mouse hover

82 views
Skip to first unread message

Miha

unread,
Mar 14, 2015, 5:52:26 AM3/14/15
to pyqt...@googlegroups.com
Hello!

I'm having some problems. I would like to print PlotCurveItem name when I click it, but with the methods I tried I get name as soon as mouse enters bounding box of the PlotCurveItem. What am I doing wrong?

I do plots by using:

class CustomPlotCurveItem(pg.PlotCurveItem):

    pltClicked = pqc.Signal()

    def __init__(self, parent = None, *args, **kwargs):
        super(CustomPlotCurveItem, self).__init__(parent, *args, **kwargs)

    def mousePressEvent(self, ev):
        super(CustomPlotCurveItem, self).mousePressEvent(ev)
        self.pltClicked.emit()

And in window:

    def do_connections:
        items=self.plot_area.items
        for item in items:
            if isinstance(item,pg.PlotCurveItem):
                self.connect(item, pqc.SIGNAL("pltClicked()"), functools.partial(self.plot_item_clicked, item))
    def plot_item_clicked(self,item):
        print(item.name())

How can I print the name only when the mouse cursor is directly under over line itself and not over bounding box?

Thank your for the help.

Miha

unread,
Mar 14, 2015, 6:29:56 AM3/14/15
to pyqt...@googlegroups.com
Nevermind....got it :)

Dne sobota, 14. marec 2015 10.52.26 UTC+1 je oseba Miha napisala:

Miha

unread,
Mar 15, 2015, 2:11:08 PM3/15/15
to pyqt...@googlegroups.com
I got a question how i did it...so here it is:

    def mouse_moved(self, evt):

        if self.plot_area.sceneBoundingRect().contains(evt):
            mousePoint = self.plot_area.vb.mapSceneToView(evt)

            #check if mouse position is contained in curve path
            for item in self.plot_area.scene().items():
                if isinstance(item, pd.PlotCurveItem):

                    if item.mouseShape().contains(mousePoint):
                        itemname=item.name()
Reply all
Reply to author
Forward
0 new messages