scene() returning None?

71 views
Skip to first unread message

Oscar Branson

unread,
Oct 17, 2018, 3:16:03 AM10/17/18
to pyqtgraph

Hello,

I'm attempting to implement an action based on sigMouseMoved, but have got seriously confused about how to access this signal.

The Project

I am creating multi-panel plots inside a larger pyqt application. To do this, I have contained everything within a  GraphicsView, which contains a central GraphicsLayout that contains the plots.

I am using PlotItem to create plots, which I then add to the GraphicsLayout using addItem.

This is all working fine, and I end up with two plots displayed - let's call them Plot1 and Plot2.

Now, I want to display the cursor position in a label, so I created a label and a mouseMoved function to update the label text.

The problem: I can't work out how to connect sigMouseMoved to my mouseMoved function.

Following the documentation and examples, I tried setting up a SignalProxy:

SignalProxy(Plot1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)

When I try to run this, I get an AttributeError telling me that 'NoneType' object has no attribute 'sigMouseMoved'. I can't work out why calling scene() on my plots returns None!

The only difference I can see from the examples is that I'm manually creating 'PlotItem' rather than pyqtgraph.plot to create my plots... but as far as I can tell the .plot function is just a wrapper for creating a PlotItem.

Any help/pointers would be greatly appreciated... this is driving me mad!

Thanks,

Oscar.

Patrick

unread,
Oct 18, 2018, 12:14:32 AM10/18/18
to pyqtgraph
Hi,

I don't think the issue is just because you create the PlotItems separately. If I change the Crosshair/Mouse interaction example lines from
p1 = win.addPlot(row=1, col=0)
p2
= win.addPlot(row=2, col=0)

to

p1 = pg.PlotItem()
p2
= pg.PlotItem()
win
.addItem(p1, row=1, col=0)
win
.addItem(p2, row=2, col=0)

then the example still works fine.


I'm taking a guess and saying you're trying to connect the signal to the PlotItem before adding it to the GraphicsLayout. Until that happens, it doesn't know what GraphicsScene it's part of.



Patrick

Oscar Branson

unread,
Oct 18, 2018, 12:37:43 AM10/18/18
to pyqtgraph
Yep - that solved it. Was trying to make the connection before adding the plots. Doh! Thanks v much.
Reply all
Reply to author
Forward
0 new messages