I would like to plot the data in ctrl function in a figure that is created in Plot class.
class Data(QWidget):
def __init__(self):
QWidget.__init__(self)
self.layout = QHBoxLayout()
button_widget = QWidget()
button_layout = QVBoxLayout()
self.btn_off = QPushButton("Off")
self.btn_off.clicked.connect(self.ctrl)
button_widget.setLayout(button_layout)
self.layout.addWidget(button_widget, stretch=1)
self.setLayout(self.layout)
def ctrl(self):
graphWidget = Plot().graphWidget
y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
x = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
graphWidget.plot(x, y)
class Plot(QWidget):
def __init__(self):
QWidget.__init__(self)
self.layout = QVBoxLayout()
button_widget = QWidget()
button_layout = QVBoxLayout()
ly_widget = QWidget()
ly = QVBoxLayout()
self.graph()
ly.addWidget(self.graphWidget)
ly_widget.setLayout(ly)
self.layout.addWidget(ly_widget)
widget2 = Data()
self.layout.addWidget(widget2, stretch=4)
self.setLayout(self.layout)
def graph(self):
self.graphWidget = pg.PlotWidget()
class MainWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
self.layout = QVBoxLayout()
bottom_widget = Plot()
self.layout.addWidget(bottom_widget, stretch=10)
self.setLayout(self.layout)
class Window(QMainWindow):
def __init__(self, widget):
QMainWindow.__init__(self)
self.setCentralWidget(widget)
widget.parent = self
app = QApplication(sys.argv)
main_widget = MainWidget()
win = Window(main_widget)
win.show()
sys.exit(app.exec_())
But graphWidget is not recognized in Data class. Can someone help me with either sending the data to the graph function and plotting them or plotting them inside the ctrl function?