本页内容

FolderDialog QML Type

原生文件夹对话框。更多...

Import Statement: import Qt.labs.platform
Inherits:

Dialog

Status: Deprecated since 6.9

自 Qt Labs Platform 6.9 起,此类型已弃用。我们强烈建议不要在新代码中使用它。

属性

详细说明

请改用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
}

可用性

目前,以下平台支持原生平台文件夹对话框:

  • Android
  • 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

此属性用于存储在确认对话框的按钮上显示的标签文本。

当设置为空字符串时,将使用底层平台的默认标签。默认标签通常为Open 。

默认值为空字符串。

另请参阅 rejectLabel 。

currentFolder : url

该属性保存对话框中当前选中的文件夹。

与folder 属性不同,currentFolder 属性会在用户于对话框中选择文件夹时实时更新,即使最终选择尚未确定。

另请参阅 folder 。

folder : url

该属性保存最终被选中的文件夹。

与currentFolder 属性不同,folder 属性不会在用户于对话框中选择文件夹时更新,而仅在最终选择确定后才会更新。也就是说,当用户点击“OK ”以确认文件夹时。此外,也可以通过处理accepted()信号来获取最终选择结果。

另请参阅 currentFolder 和accepted()。

options : flags

此属性包含影响对话框外观和风格的各种选项。

默认情况下,所有选项均处于禁用状态。

应在显示对话框之前设置这些选项。在对话框可见时进行设置,不能保证会立即对对话框产生影响(具体取决于选项和平台)。

可用选项:

常量描述
FolderDialog.ShowDirsOnly仅在文件夹对话框中显示目录。默认情况下,文件夹和目录都会显示。
FolderDialog.DontResolveSymlinks在文件夹对话框中不解析符号链接。默认情况下会解析符号链接。
FolderDialog.ReadOnly表示该对话框不允许创建目录。

rejectLabel : string

该属性用于存储在用于关闭对话框的按钮上显示的标签文本。

当设置为空字符串时,将使用底层平台的默认标签。默认标签通常为Cancel 。

默认值为空字符串。

另请参阅 acceptLabel 。

© 2026 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.