当前位置 : 主页 > 手机教程 > 手机资讯 >

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

来源:互联网 收集:自由互联 发布时间:2023-01-20
主界面如下 打开单个文件配置 FileDialog { id: idFileOpenOne fileMode: FileDialog.OpenFile nameFilters: ["Pictures (*.png *.jpg *.gif *.bmp)", "All (*.*)"] options :FileDialog.ReadOnly } 打开多个文件配置 FileDialog { id:

主界面如下 

 打开单个文件配置

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

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

上一篇:JavaScriptconsole对象与控制台使用示例详解
下一篇:没有了
网友评论