Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

python - PySide2: How to prevent QFileDialog to close Sub-QMainWidget

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...