I'm trying to use PyQT5 to generate a scrollable window for my graph that I'm generating however, everytime it's generated, I get the error: -1073741819 (0xC0000005) and it ends my program execution.
The code for the window is:
class ScrollableWindow(QtWidgets.QMainWindow):
def __init__(self, fig):
self.qapp = QtWidgets.QApplication([])
QtWidgets.QMainWindow.__init__(self)
self.widget = QtWidgets.QWidget()
self.setCentralWidget(self.widget)
self.widget.setLayout(QtWidgets.QVBoxLayout())
self.widget.layout().setContentsMargins(0,0,0,0)
self.widget.layout().setSpacing(0)
self.fig = fig
self.canvas = FigureCanvas(self.fig)
self.canvas.draw()
self.scroll = QtWidgets.QScrollArea(self.widget)
self.scroll.setWidget(self.canvas)
self.nav = NavigationToolbar(self.canvas, self.widget)
self.widget.layout().addWidget(self.nav)
self.widget.layout().addWidget(self.scroll)
self.show()
exit(self.qapp.exec_())
And I'm calling it as (fund_figs is the graph name):
a = ScrollableWindow(fund_figs)
print(a)
Any help is appreciated.
I'm not great with this side of Python, but here are two things I noticed that may help:
import QtWidgets
If you don't want the error to end your program, try doing this:
class ScrollableWindow(QtWidgets.QMainWindow):
def __init__(self, fig):
try:
#enter code here
except Exception as e:
print("Here is the error: {} " .format(e))
I don't know if this helped at all, sorry if it didn't, but I do hope it educated you in some form or another.
It was an issue with PyQT5 which when generating a window before it, closing it and generating a scrollable window causes the program to crash.
Basically, there was another scatter plot before it which closes before the one in question is generated. It caused the program to crash, I'm assuming its some kind of bug.
User contributions licensed under CC BY-SA 3.0