Pyqt4, Generating Multiple Instances Of The Same Widget?
I am creating a PyQt4 gui that allows the user in a qmainwindow to input some initial parameters and then click a start button to begin a program. When they click the start button
Solution 1:
I am guessing that you are saving the reference to newly created window in the same variable. If you want to create multiple windows, try to save the reference to that window in a separate variable, i.e each window should have it's own reference variable.
defshowWindow(self):
self.child = Window(self)
self.child.show()
If this is your situation, the first window will loose it's reference as soon as the second time showWindow()
executes. Because the self.child
will contain the reference to second window, resulting in closing the first window, because the first window has no reference reference. As soon as the widget looses reference in Qt, the widget will be destroyed. To overcome this problem maintain a list of variables:
# declare a list in __init__ as self.widgetList = []defshowWindow(self):
win = Window(self):
win.show()
self.widgetList.append(win)
Post a Comment for "Pyqt4, Generating Multiple Instances Of The Same Widget?"