Reputation: 469
I have this code in main.qml:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Controls 2.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Test")
FileDialog {
id: fileDialog
folder: shortcuts.home
visible: true
title: "Please choose an image"
nameFilters: ["Image files (*.jpg *.png)", "All files (*)"]
onAccepted: {
image.source = fileDialog.fileUrl
}
}
Image {
id: image
anchors.centerIn: parent
}
}
When I run it by pressing Run in QtCreator, I get a file dialog with no files listed.
Screenshot 1
It lists files if I run it as qmlscene-qt5 main.qml
, but this way I have no filters available (All Files only).
Screenshot 2
Upvotes: 1
Views: 106
Reputation: 243965
You have to make it visible when the item has been completely created:
FileDialog {
id: fileDialog
folder: shortcuts.home
// visible: true <--- ---
title: "Please choose an image"
nameFilters: [ "Image files (*.jpg *.png)", "All files (*)" ]
onAccepted: {
image.source = fileDialog.fileUrl
}
Component.onCompleted: visible = true // <--- +++
}
Upvotes: 1