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文件對話框內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- QML中動態與靜態模型應用詳解
- QT quick-Popup彈出窗口自定義的實現
- C++數據模型應用在QML委托代理機制中
- 教你如何使用qt quick-PathView實現好看的home界面
- 使用qt quick-ListView仿微信好友列表和聊天列表的示例代碼