Qt6基于Qml的文件对话框演示效果

主界面如下 

Qt6基于Qml的文件对话框演示效果_第1张图片

 打开单个文件配置

FileDialog {
        id: idFileOpenOne
        fileMode: FileDialog.OpenFile
        nameFilters: ["Pictures (*.png *.jpg *.gif *.bmp)", "All (*.*)"]
        options :FileDialog.ReadOnly
    }

打开多个文件配置

FileDialog {
        id: idFileOpenMore
        fileMode: FileDialog.OpenFiles
        nameFilters: ["Pictures (*.png *.jpg *.gif *.bmp)", "All (*.*)"]
        options :FileDialog.ReadOnly
    }

保存文件配置

FileDialog {
        id: idFileSave
        nameFilters: ["Pictures (*.png *.jpg *.gif *.bmp)", "All (*.*)"]
        fileMode: FileDialog.SaveFile
    }

三个按钮布局

Row{
        anchors.centerIn: parent
        spacing: 30
        Button{
            text: qsTr("Open")
            height: 48
            width: 120
            MouseArea{
                anchors.fill: parent
                onClicked: {
                   idFileOpenOne.open();
                }
            }
        }
        Button{
            text: qsTr("Open More ...")
            height: 48
            width: 120
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    idFileOpenMore.open();
                }
            }
        }
        Button{
            text: qsTr("Save")
            height: 48
            width: 120
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    idFileSave.open();
                }
            }
        }
    }

点击效果展示:

Qt6基于Qml的文件对话框演示效果_第2张图片

Qt6基于Qml的文件对话框演示效果_第3张图片

完整源码:

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import Qt.labs.platform 1.1
 
ApplicationWindow {
    visible: true
    width: 600
    height: 200
    title: qsTr("Qt6基于Qml的文件对话框演示")
    Row{
        anchors.centerIn: parent
        spacing: 30
        Button{
            text: qsTr("Open")
            height: 48
            width: 120
            MouseArea{
                anchors.fill: parent
                onClicked: {
                   idFileOpenOne.open();
                }
            }
        }
        Button{
            text: qsTr("Open More ...")
            height: 48
            width: 120
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    idFileOpenMore.open();
                }
            }
        }
        Button{
            text: qsTr("Save")
            height: 48
            width: 120
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    idFileSave.open();
                }
            }
        }
    }
 
    FileDialog {
        id: idFileOpenOne
        fileMode: FileDialog.OpenFile
        nameFilters: ["Pictures (*.png *.jpg *.gif *.bmp)", "All (*.*)"]
        options :FileDialog.ReadOnly
    }
 
    FileDialog {
        id: idFileOpenMore
        fileMode: FileDialog.OpenFiles
        nameFilters: ["Pictures (*.png *.jpg *.gif *.bmp)", "All (*.*)"]
        options :FileDialog.ReadOnly
    }
    FileDialog {
        id: idFileSave
        nameFilters: ["Pictures (*.png *.jpg *.gif *.bmp)", "All (*.*)"]
        fileMode: FileDialog.SaveFile
    }
}

到此这篇关于Qt6基于Qml的文件对话框演示的文章就介绍到这了,更多相关Qml文件对话框内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(Qt6基于Qml的文件对话框演示效果)