FolderDialog QML Type
本地文件夹对话框。更多
Import Statement: | import Qt.labs.platform |
Inherits: | |
Status: | Deprecated since 6.9 |
自 Qt.labs.platform 6.9 起,该类型已被弃用。我们强烈建议不要在新代码中使用它。
属性
- acceptLabel : string
- currentFolder : url
- folder : url
- options : flags
- rejectLabel : string
详细说明
使用QtQuick.Dialogs::FolderDialog 代替。
FolderDialog 类型为本地平台文件夹对话框提供了 QML API。
要显示文件夹对话框,请构建 FolderDialog 的实例,设置所需的属性,然后调用open() 。currentFolder 属性可用于确定对话框中当前选定的文件夹。只有在接受对话框做出最终选择后,才会更新folder 属性。
MenuItem { text: "Open..." onTriggered: folderDialog.open() } FolderDialog { id: folderDialog currentFolder: viewer.folder folder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] } MyViewer { id: viewer folder: folderDialog.folder }
可用性
本机平台文件夹对话框目前在以下平台上可用:
- 安卓
- iOS
- Linux(使用 GTK+ 平台主题运行时)
- MacOS
- Windows
在没有本地实现的平台上,Qt Labs Platform 模块使用Qt Widgets 作为备用。因此,使用Qt Labs Platform 模块中类型的应用程序应链接到 QtWidgets 并使用QApplication 而不是QGuiApplication 。
要链接 QtWidgets 库,请在 qmake 项目文件中添加以下内容:
QT += widgets
在main()
中创建QApplication 的实例:
#include <QApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
注意: Qt.labs 模块中的类型不保证在未来版本中保持兼容。
另请参阅 QtQuick.Dialogs::FolderDialog,FileDialog, 和StandardPaths 。
属性文档
acceptLabel : string |
currentFolder : url |
folder : url |
该属性保存最终接受的文件夹。
与currentFolder 属性不同,folder
属性不会在用户在对话框中选择文件夹时更新,而只会在做出最终选择后更新。也就是说,当用户单击OK 接受文件夹时,该属性才会更新。或者,也可以处理accepted() 信号来获取最终选择。
另请参阅 currentFolder 和accepted()。
options : flags |
该属性包含影响对话框外观的各种选项。
默认情况下,所有选项都是禁用的。
应在显示对话框之前设置选项。如果在对话框可见时设置这些选项,则不能保证立即对对话框产生影响(取决于选项和平台)。
可用选项
常量 | 说明 |
---|---|
FolderDialog.ShowDirsOnly | 在文件夹对话框中只显示目录。默认情况下同时显示文件夹和目录。 |
FolderDialog.DontResolveSymlinks | 在文件夹对话框中不解析符号链接。默认情况下会解析符号链接。 |
FolderDialog.ReadOnly | 表示对话框不允许创建目录。 |
rejectLabel : string |
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.