主界面如下
打开单个文件配置
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文件对话框内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!