Skip to content

Commit 2e96ae8

Browse files
committed
Add QmlFileDialog
1 parent fa3cbe8 commit 2e96ae8

File tree

7 files changed

+118
-0
lines changed

7 files changed

+118
-0
lines changed

QmlFileDialog/QmlFileDialog.pro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick widgets
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlFileDialog/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QApplication app(argc, argv);
15+
QQmlApplicationEngine engine;
16+
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
17+
return app.exec();
18+
}

QmlFileDialog/main.qml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.0
10+
import QtQuick.Layouts 1.0
11+
import Qt.labs.platform 1.0
12+
13+
ApplicationWindow {
14+
visible: true
15+
width: 400
16+
height: 300
17+
title: qsTr("Qml文件对话框")
18+
19+
20+
Column{
21+
anchors.centerIn: parent
22+
23+
Button{
24+
text: qsTr("打开文件")
25+
height: 48
26+
width: 120
27+
MouseArea{
28+
anchors.fill: parent
29+
onClicked: {
30+
fileDialog1.open()
31+
}
32+
}
33+
}
34+
Button{
35+
text: qsTr("打开多个文件")
36+
height: 48
37+
width: 120
38+
MouseArea{
39+
anchors.fill: parent
40+
onClicked: {
41+
fileDialog2.open()
42+
}
43+
}
44+
}
45+
Button{
46+
text: qsTr("保存文件")
47+
height: 48
48+
width: 120
49+
MouseArea{
50+
anchors.fill: parent
51+
onClicked: {
52+
fileDialog3.open()
53+
}
54+
}
55+
}
56+
}
57+
58+
FileDialog {
59+
id: fileDialog1
60+
fileMode: FileDialog.OpenFile
61+
nameFilters: ["图像文件 (*.png *.jpg *.gif *.bmp)", "全部文件 (*.*)"]
62+
options :FileDialog.ReadOnly
63+
}
64+
FileDialog {
65+
id: fileDialog2
66+
fileMode: FileDialog.OpenFiles
67+
nameFilters: ["图像文件 (*.png *.jpg *.gif *.bmp)", "全部文件 (*.*)"]
68+
options :FileDialog.ReadOnly
69+
}
70+
FileDialog {
71+
id: fileDialog3
72+
nameFilters: ["图像文件 (*.png *.jpg *.gif *.bmp)", "全部文件 (*.*)"]
73+
fileMode: FileDialog.SaveFile
74+
}
75+
}

QmlFileDialog/qml.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
</qresource>
5+
</RCC>

QmlFileDialog/show.gif

119 KB
Loading

QtQuickExamples.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ SUBDIRS += QmlUpDownRefresh
4545
SUBDIRS += QmlListViewDragDrop
4646
SUBDIRS += QmlCanvasWaveProgress
4747
SUBDIRS += QmlColorDialog
48+
SUBDIRS += QmlFileDialog
49+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ QmlColorDialog: Qml选择颜色对话框
212212
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlColorDialog/show.gif?raw=true)
213213

214214

215+
QmlFileDialog: Qml文件对话框
216+
217+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlFileDialog/show.gif?raw=true)
218+
219+
215220

216221

217222
***

0 commit comments

Comments
 (0)