Issue
I'm creating a dictionary of pyqtgraph.plot() items, and then later adding those items to a tabbed PyQt window. However, as soon as these objects are created, a window is generated as well. I'm able to call the win.hide() function to get rid of these windows, but they still pop up initially. Is there any way to prevent the window from popping up upon creation of the plot objects?
import pyqtgraph as pg
#Generate dictionary containing pyqtgraph plots
plot_dict = {'plot_1': pg.plot(),
'plot_2': pg.plot(),
'plot_3': [pg.plot()'
}
#Hide plot windows after they are generated
for plot in plot_dict:
plot.win.hide()
Basically: is there a flag I can include with pg.plot() that prevents the windows from ever showing?
Solution
plot()
is just a helper function that shows PlotWindow
s. (see plot).
PlotWindow
is a class that inherits from PlotWidget
and shows itself in a window. (It also calls show()
and does some other stuff like setting the title and resizing).
Both of these create the QApplication
if it does not exist with mkQApp()
.
fyi:
class PlotWindow(PlotWidget):
def __init__(self, title=None, **kargs):
mkQApp()
self.win = QtGui.QMainWindow()
PlotWidget.__init__(self, **kargs)
self.win.setCentralWidget(self)
for m in ['resize']:
setattr(self, m, getattr(self.win, m))
if title is not None:
self.win.setWindowTitle(title)
self.win.show()
and
def mkQApp():
global QAPP
inst = QtGui.QApplication.instance()
if inst is None:
QAPP = QtGui.QApplication([])
else:
QAPP = inst
return QAPP
So the solution is to use PlotWidget
directly and call show()
yourself when you want to see it. You also have to create the QApplication
yourself.
import pyqtgraph as pg
if __name__ == '__main__':
app = pg.mkQApp()
plot_dict = {'plot_1': pg.PlotWidget(),
'plot_2': pg.PlotWidget(),
'plot_3': pg.PlotWidget()
}
plot_dict['plot_1'].show() # manually call show()
app.exec()
Answered By - Jonas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.