可以使用“打开文件"对话框选择文件夹吗? [英] can the Open File dialog be used to select a Folder?

查看:120
本文介绍了可以使用“打开文件"对话框选择文件夹吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览文件夹" Windows对话框非常不便,因为:

  • 它没有路径"框,我可以在其中粘贴所需的路径(例如,来自Total Commander)
  • 它始终从关闭的桌面启动

是否可以使用打开文件"对话框(更好)来选择文件夹?一些标志或选项之类的东西?

上下文:使用Python和Qt编写的 Calibre eLibrary管理器. >

当前显示为左侧.我希望它显示在右侧

甚至更好,如打开文件"对话框:

解决方案

您可以尝试以下方法:

QString QFileDialog::getExistingDirectory ( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly ) [static]

该目录用于选择目录,并会弹出一个对话框,如您最后显示的那样.

演示:

 QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
                                             "/home",
                                             QFileDialog::ShowDirsOnly
                                             | QFileDialog::DontResolveSymlinks);

The "Browse For Folder" Windows dialog is very inconvenient because:

  • it has no Path box where I can paste the path I want (eg from Total Commander)
  • it always starts from the Desktop with everything closed

Is there a way to use the "Open File" dialog (which is much better) to select a Folder? Some flag or option or something?

Context: the calibre eLibrary manager which is written in Python and Qt.

It currently displays as on the left. I'd like it to display as on the right

or even better, as the Open File dialog:

解决方案

You can try this one:

QString QFileDialog::getExistingDirectory ( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly ) [static]

This one is used to choose a directory, and will popup a dialog like you show at last.

Demo:

 QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
                                             "/home",
                                             QFileDialog::ShowDirsOnly
                                             | QFileDialog::DontResolveSymlinks);

这篇关于可以使用“打开文件"对话框选择文件夹吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆