Reopen notice
I don't know where else to put this... I will remove it after the question has been reopened. It has been closed (single-handedly) obviously only because I posted a link to another SO thread in the comments. This link however was not targeted to answer this question, but to target an additonal question in the comments. This question has not been answered by the other question but rather by the comment. It is unfair against @icwebndev who answered the question in the comment and should receive the chance to actually really answer the question.
I do have a PySide2/PyQT5 based application that works fine so far. On the main window, when I press a button, a widget (QDialog) is opened which does some initialization steps in its __init__()
method.
When this window is closed (using its close()
) method, and reopened later, the __init__() is not called anymore, only the
show()` method. Is there a way to reinitialize the Dialog every time its opened?
Edit: When writing the question it occurred to me that I can simply move the relevant code to the show()
function. On the other hand, I somehow have the feeling that this it not the intended way to do so.
Below there is the minimized code. Console output when opening the window for the first time is:
Hello_show
Hello_init
The second time its only
Hello_show
mainWindow.py
def startWeighInButtonPressed(self):
weighInWindow = WeighInWidget(parent=self, app=self.app)
weighInWindow.show()
weighInWidget.py
class WeighInWidget(QtWidgets.QDialog):
app = None # type: QApplication
def __init__(self, parent=None, app=None):
# Get application instance
self.app = app
# Call parent
super(WeighInWidget, self).__init__(parent)
# Do some other init steps
if initFailed
error_msg = QtWidgets.QErrorMessage()
error_msg.showMessage('Some Error message')
error_msg.exec_()
self.close()
return
# Setup UI
self.ui = Ui_weighInWidget()
self.ui.setupUi(self)
print('Hello_init')
def show(self):
print('Hello_show')
super().show()
def close(self):
self.deleteLater()
super().close()