Qt6基于Qml的文件对话框演示效果
作者:江鸟木又
这篇文章主要介绍了Qt6基于Qml的文件对话框演示,包括打开单个文件配置和打开多个文件配置及保存文件配置的方法,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下
主界面如下
打开单个文件配置
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文件对话框内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!