Skip to content

Commit

Permalink
Add QmlFileDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengtianzuo committed Dec 9, 2017
1 parent fa3cbe8 commit 2e96ae8
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
13 changes: 13 additions & 0 deletions QmlFileDialog/QmlFileDialog.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#-------------------------------------------------
#
# Copyright (C) 2003-2103 CamelSoft Corporation
#
#-------------------------------------------------

QT += qml quick widgets

CONFIG += c++11

SOURCES += main.cpp

RESOURCES += qml.qrc
18 changes: 18 additions & 0 deletions QmlFileDialog/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*!
*@file main.cpp
*@brief 程序主文件
*@version 1.0
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
*@author zhengtianzuo
*/
#include <QApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
75 changes: 75 additions & 0 deletions QmlFileDialog/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*!
*@file main.qml
*@brief 主文件
*@version 1.0
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
*@author zhengtianzuo
*/
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import Qt.labs.platform 1.0

ApplicationWindow {
visible: true
width: 400
height: 300
title: qsTr("Qml文件对话框")


Column{
anchors.centerIn: parent

Button{
text: qsTr("打开文件")
height: 48
width: 120
MouseArea{
anchors.fill: parent
onClicked: {
fileDialog1.open()
}
}
}
Button{
text: qsTr("打开多个文件")
height: 48
width: 120
MouseArea{
anchors.fill: parent
onClicked: {
fileDialog2.open()
}
}
}
Button{
text: qsTr("保存文件")
height: 48
width: 120
MouseArea{
anchors.fill: parent
onClicked: {
fileDialog3.open()
}
}
}
}

FileDialog {
id: fileDialog1
fileMode: FileDialog.OpenFile
nameFilters: ["图像文件 (*.png *.jpg *.gif *.bmp)", "全部文件 (*.*)"]
options :FileDialog.ReadOnly
}
FileDialog {
id: fileDialog2
fileMode: FileDialog.OpenFiles
nameFilters: ["图像文件 (*.png *.jpg *.gif *.bmp)", "全部文件 (*.*)"]
options :FileDialog.ReadOnly
}
FileDialog {
id: fileDialog3
nameFilters: ["图像文件 (*.png *.jpg *.gif *.bmp)", "全部文件 (*.*)"]
fileMode: FileDialog.SaveFile
}
}
5 changes: 5 additions & 0 deletions QmlFileDialog/qml.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
Binary file added QmlFileDialog/show.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions QtQuickExamples.pro
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ SUBDIRS += QmlUpDownRefresh
SUBDIRS += QmlListViewDragDrop
SUBDIRS += QmlCanvasWaveProgress
SUBDIRS += QmlColorDialog
SUBDIRS += QmlFileDialog

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ QmlColorDialog: Qml选择颜色对话框
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlColorDialog/show.gif?raw=true)


QmlFileDialog: Qml文件对话框

![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlFileDialog/show.gif?raw=true)




***
Expand Down

0 comments on commit 2e96ae8

Please sign in to comment.