QDialog override reject when loading .ui file
-
I have a custom dialog that is based on QDialog class. I load .ui file to python.
# Main window class class MyDialog(QDialog): def __init__(self): super().__init__() self.load_ui() self.ui.show() # Load UI from file def load_ui(self): loader = QUiLoader() path = os.fspath(Path(__file__).resolve().parent / 'ui' / 'dialog.ui') ui_file = QFile(path) ui_file.open(QFile.ReadOnly) self.ui = loader.load(ui_file, parentWidget = self) ui_file.close() # Override reject def reject(self): print("reject")I call it with
self.testwidget = MyDialog()and it opens well. But reject method is not part of the UI. How can I add reject method if UI is loaded from .ui file? I want to do something on reject callback. -
Hi,
The recommended way to use designer based widget is to generate the Python code from your ui file.
-