I have a superclass that inherits from QMainWindow, and its purpose is to call a function inside the Connection function instead of the normal CloseEvent (which would close my whole app) that displays the starter and kills the caller, and only if it sends Close, to actually close the app.
Anyway, I am now trying to call a QFileDialog in one of the derived classes inside a function, as soon as it closes (accepted, rejected alike), the CloseEvent is fired. The problem here is that my class is recognized as the caller and I don't see any way to distinguish the Close event from the dialog and the MainWindow. The event has no method or attribute "sender", and self of course always remains on the QMainWindow class (or its derived superclass)...
My Superclass:
#import 3rd-Party-Libs
from PySide2.QtWidgets import QMainWindow
class SuperMiniApp(QMainWindow):
'''SuperApp for the common MiniApp-Functions'''
def __init__(self, parent):
'''initialize this class'''
super(SuperMiniApp, self).__init__(parent)
def closeEvent(self, event):
'''Overwrite QMainWindow's closeEvent, to prevent it from closing the whole App'''
#if not from starter catch the Close-Event
if (self == self.parent()._starter):
event.accept()
else:
self.parent().close_MiniApp(self, event)
calling of the QFileDialog:
def call_dialog(self):
title = 'Choose One'
datatypes = '*.*'
dir = os.getcwd()
return(QFileDialog.getOpenFileName(self, title, dir, datatypes)[0])
question from:
https://stackoverflow.com/questions/65876781/pyside2-how-to-prevent-qfiledialog-to-close-sub-qmainwidget 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…