|
1Qter豆
本帖最后由 king23 于 2018-6-7 22:49 编辑
希望实现的是,在open后选择若干文件,确定,然后在界面的空白的地方,每个文件路径显示一行,如果路径很长希望能自动换行。
关于动态添加好像有两种方法 一个是使用 js ,另一个是使用 c++ binding. 不知我了解到是否准确。希望使用后一种方法。
上面描述的功能我不知道如何实现。请高手帮助。
- import QtQuick 2.4
- import QtQuick.Controls 1.4
- import QtQuick.Dialogs 1.1
- import QtQuick.Layouts 1.1
- Item
- {
- id:root
- width: 400
- height: 800
- // anchors.fill: parent
- //! [filedialog]
- FileDialog {
- id: fileDialog
- modality: Qt.NonModal
- title: "Choose some files"
- selectExisting: true
- selectMultiple: true
- // selectFolder: fileDialogSelectFolder.checked
- nameFilters: [ "Image files (*.png *.jpg)", "All files (*)" ]
- selectedNameFilter: "All files (*)"
- sidebarVisible: true
- onAccepted: {
- // console.log("Accepted: " + fileUrls)
- for (var i =0 ; i < fileUrls.length; i++) {
- console.log("Accepted: " + fileUrls[i])
- }
- }
- onRejected: { console.log("Rejected") }
- }
- //! [filedialog]
- ColumnLayout{
- anchors.fill: parent
- RowLayout {
- Label {
- Layout.alignment: Qt.AlignCenter
- text: qsTr("File path :")
- }
- TextField {
- id: filePathField
- Layout.alignment: Qt.AlignCenter
- Layout.preferredWidth : 200
- text: fileDialog.fileUrls
- }
- Button {
- Layout.alignment: Qt.AlignCenter
- text: "Open"
- onClicked: fileDialog.open()
- }
- }
- Text {
- text: fileDialog.fileUrls[0]
- }
- // Label {
- // text: {
- // for (var i = 0; fileDialog.fileUrls.length; i++){
- // fileDialog.fileUrls[i]
- // }
- // }
- // }
- Rectangle {
- Layout.fillHeight: true
- }
- }
- }
复制代码
工程已添加到附件
|
|