PyQt5 QFileDialog.getExistingDirectory
date
:2021-06-11
问题说明
获取图像所在文件夹,然后返回路径将其更新到textBrowser
中。测试发现win10下会选择完路径后很久才返回文件夹地址,但该现象出现在我更新系统后,不知原因。
img_dir_path = QFileDialog.getExistingDirectory(self,
caption='Select Image Directory',
directory=os.getcwd())
self.image_path_line.setText(str(img_dir_path))
解决办法
The QFileDialog constructor creates a Qt dialog, whereas the static functions (like getSaveFileName) will create a native one (unless the DontUseNativeDialog option is set to True).
无法保证系统的NativeDialog比qt自带的快,但是测试发现qt自带的速度更快。所以有解决办法:
img_dir_path = QFileDialog.getExistingDirectory(self,
caption='Select Image Directory',
directory=os.getcwd(),
options=QFileDialog.DontUseNativeDialog)
self.image_path_line.setText(str(img_dir_path))
或者直接输入文件夹路径。