[英]PyQt5 - how to bring the Qfiledialog to the front?
My code uses PyQt to open up a folder select dialog. 我的代码使用PyQt打开一个文件夹选择对话框。 Once a folder is selected it is minimized.
选择文件夹后,它将最小化。 I'd like for the dialog to pop up in front of any other windows.
我希望对话框在其他任何窗口前弹出。 I haven't been able to find a solution yet.
我还没有找到解决方案。 Any suggestions?
有什么建议么?
from sys import executable, argv
from subprocess import check_output
from PyQt5.QtWidgets import QFileDialog, QApplication
def gui_fname(directory=''):
file = check_output([executable, __file__, directory])
return file.strip()
if __name__ == "__main__":
directory = argv[1]
app = QApplication([directory])
folderpath = QFileDialog.getExistingDirectory(None, "Select folder")
I think your problem comes from the "None" in the following function. 我认为您的问题来自以下功能中的“无”。
folderpath = QFileDialog.getExistingDirectory(None, "Select folder")
The dialog modality cannot be set because it has no parent. 无法设置对话框模态,因为它没有父级。 Usually, instead of
None
we have self
. 通常,我们拥有
self
而不是None
。
EDIT: Of cource app is not inheriting from QWidget. 编辑:当然应用程序不是从QWidget继承的。 Sorry about that.
对于那个很抱歉。
use this instead. 改用这个。 I tested it an it work:
我测试了它的工作原理:
import sys
from subprocess import check_output
from PyQt5.QtWidgets import QFileDialog, QApplication, QWidget
def gui_fname(directory=''):
file = check_output([executable, __file__, directory])
return file.strip()
if __name__ == "__main__":
app = QApplication(sys.argv)
wid = QWidget()
folderpath = QFileDialog.getExistingDirectory(wid, "Select folder")
sys.exit(app.exec_())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.