Export menu window detection

47 views
Skip to first unread message

Gáll Péter

unread,
Aug 8, 2019, 5:48:20 AM8/8/19
to pyqtgraph
Hi!

I'm plotting real time data with pyqtgraph and I can pause it with a button in the GUI.
I would like to pause the plotting, when Export menu is clicked from the context menu.
Is there any way to detect that the export menu is opened?
Thanks.

Patrick

unread,
Aug 8, 2019, 10:11:13 PM8/8/19
to pyqtgraph
Hi,

Not sure if this is the cleanest way to do it, but you can connect to the GraphicsScene menu item signal, something like:

class TestPlot(pg.GraphicsLayoutWidget):
   
def __init__(self):
       
# ... usual init stuff
       
self.ci.scene().contextMenu[0].triggered.connect(self.export_clicked)

   
def export_clicked(self):
       
print("Export")

Note, ci is the central item (a GraphicsLayout) in the GraphicsLayoutWidget. The scene() method gets the associated GraphicsScene. If you're not using a GraphicsLayoutWidget then finding the GraphicsScene might be a little different.

Patrick

Gáll Péter

unread,
Aug 9, 2019, 4:26:57 AM8/9/19
to pyqtgraph
Thanks, it worked for me. I'm using pg.Plotwidget(), so I get the signal like that:
self.power_graph.sceneObj.contextMenu[0].triggered.connect(self.export_clicked)

Is there a signal that detects closing the window too? I tried contextMenu[0].detroyed, but is did not work.

Peter

Carlos Pascual

unread,
Aug 19, 2019, 4:15:49 AM8/19/19
to pyqt...@googlegroups.com, Gáll Péter
Assuming the context menu is a QMenu, then you have the `aboutToHide` signal:
https://doc.qt.io/qt-5/qmenu.html#signals
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
ALBA Synchrotron [http://www.albasynchrotron.es]
Carrer de la Llum 2-26
E-08290 Cerdanyola del Valles (Barcelona), Spain
E-mail: cpas...@cells.es
Phone: +34 93 592 4428
+----------------------------------------------------+
Reply all
Reply to author
Forward
0 new messages