python - PySide2:如何防止 QFileDialog 关闭 Sub-QMainWidget
问题描述
我有一个继承自 QMainWindow 的超类,它的目的是调用 Connection 函数中的一个函数,而不是显示启动器并杀死调用者的普通 CloseEvent (这将关闭我的整个应用程序),并且只有当它发送关闭时,实际关闭应用程序。
无论如何,我现在正试图在函数内的一个派生类中调用 QFileDialog,只要它关闭(接受、拒绝),就会触发 CloseEvent。这里的问题是我的类被识别为调用者,我看不出有任何方法可以将 Close 事件与对话框和 MainWindow 区分开来。该事件没有方法或属性“发送者”,并且 self 当然始终保留在 QMainWindow 类(或其派生的超类)中......
我的超类:
#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)
调用 QFileDialog:
def call_dialog(self):
title = 'Choose One'
datatypes = '*.*'
dir = os.getcwd()
return(QFileDialog.getOpenFileName(self, title, dir, datatypes)[0])
解决方案
推荐阅读
- kubernetes - 在 kubernetes 中创建一个 JWK 服务器来服务密钥
- arrays - 如何过滤与字符串匹配的数组中的数据?
- javascript - 刷新网页后无法恢复聊天(对话流)
- node.js - GCP Pubsub 批量发布触发比实际消息数量多 3 到 4 倍的时间消息
- jquery - $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1) 搜索不适用于几个字母
- vue.js - 渲染大量 Svg 时 Vue.js 会变慢
- maven-gpg-plugin - 在 Maven 发布期间跳过 GPG 密钥
- javascript - 我可以同时修改 HTML 元素的属性吗?
- flutter - 如何在 Flutter PWA 中读取网络上的 .txt 文件?
- wordpress - 是否有解决方案 Wordpress 5.8 与小部件不兼容?