Skip to content

Instantly share code, notes, and snippets.

@stephenquan
Last active April 4, 2018 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenquan/142b2f60ab6b83e4b024f3a6de247573 to your computer and use it in GitHub Desktop.
Save stephenquan/142b2f60ab6b83e4b024f3a6de247573 to your computer and use it in GitHub Desktop.
qml-image-filedialog-sample.qml
// This sample allows you to pick and view an image from your pictures folder
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.3
Item {
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
RowLayout {
Layout.fillWidth: true
TextField {
id: textField
Layout.fillWidth: true
placeholderText: qsTr("Enter image's URL")
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
Button {
text: "..."
onClicked: fileDialog.open()
}
}
Image {
id: image
Layout.fillWidth: true
Layout.fillHeight: true
source: textField.text
fillMode: Image.PreserveAspectFit
}
}
FileDialog {
id: fileDialog
folder: shortcuts.pictures
onAccepted: textField.text = fileDialog.fileUrl
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment