gpt4 book ai didi

linux - 为什么 PyQt5 QFileDialog.getExistingDirectory 看不到 ~/.config/subdirectory?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:04:17 26 4
gpt4 key购买 nike

在 Python2.7 和 PySide 下,我可以指向 ~/.config/的子目录。但是,当我移动到 Python3 和 PyQt5 时,我可以打开 ~/.config/但不能打开它的子​​目录......(所有目录都有 drwxr-xr-x 权限并且没有特殊的chattr 东西或 ACL 东西正在发生。)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Arch Linux (up-to-date)
# Python 3.6.5
# python-pyqt5 5.10.1-3

import os
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

app = QApplication(sys.argv)

# Succeeds. (Lists three files in the autostart directory.)
wd = os.path.expanduser("~/.config/autostart")
os.system("ls {0}".format(wd))

# Fails. Opens to ~/
x = QFileDialog.getExistingDirectory(caption="Choose presets...", directory=wd)

wd = os.path.expanduser("~/.config")

# Succeeds. Opens at ~/.config/
x = QFileDialog.getExistingDirectory(caption="Choose presets...", directory=wd)

# Succeeds. Opens at ~/Documents/Volunteer
wd = os.path.expanduser("~/Documents/Volunteer")
x = QFileDialog.getExistingDirectory(None, "Choose presets...", wd)

最佳答案

而且,感谢@ekhumoro,我们有一个赢家!告诉 QFileDialog 不要使用 native 对话框就可以了。具体来说:

#!/usr/bin/evn python3
# -*- coding: utf-8 -*-

# Arch Linux (up-to-date)
# Python 3.6.5
# python-pyqt5 5.10.1-3

import os
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

app = QApplication(sys.argv)

# Succeeds. (Lists three files in the autostart directory.)
wd = os.path.expanduser("~/.config/autostart")
os.system("ls {0}".format(wd))

# SUCCEEDS (where it previously failed)
x = QFileDialog.getExistingDirectory(caption="Choose presets...", directory=wd,
options=QFileDialog.DontUseNativeDialog)

关于linux - 为什么 PyQt5 QFileDialog.getExistingDirectory 看不到 ~/.config/subdirectory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50635804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com