Qml文件对话框

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Qml文件对话框

江鸟木又   2022-10-15 我要评论

主界面如下 

 打开单个文件配置

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();
                }
            }
        }
    }

点击效果展示:

完整源码:

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
    }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们