QML FileDialog issue - qt

I am trying to use the FileDialog component in QML.
I have done exactly the same code that is in the Qt documentation at the link http://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html and it does not show the dialog and returns the error: QFileInfo::absolutePath: Constructed with empty filename. I tried to write a simple code to test it and the return was the same error. My code is below.
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.2
Window {
visible: true
width: 360
height: 640
maximumHeight: 640
minimumHeight: 640
maximumWidth: 360
minimumWidth: 360
title: "Acessar Galeria Test"
Rectangle {
id: principal
anchors.fill: parent
FileDialog {
id: fileDialog
title: "Please choose a file"
folder: shortcuts.home
visible: true
}
}
}

Answering my own question:
FileDialog visible property cannot be true while the component is not complete. So the code must be like below:
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.2
Window {
visible: true
width: 360
height: 640
maximumHeight: 640
minimumHeight: 640
maximumWidth: 360
minimumWidth: 360
title: "Acessar Galeria Test"
Rectangle {
id: principal
anchors.fill: parent
FileDialog {
id: fileDialog
title: "Please choose a file"
folder: shortcuts.home
visible: false
}
}
Component.onCompleted: {
fileDialog.visible = true;
}
}

Related

Display Rectangle outside of parent or Window [duplicate]

I need to have a Popup that stays visible outside the bounds of the main window.
I couldn't find anything in the Qt documentation.
This is the code:
import QtQuick 2.15
import QtQuick.Window 2.2
import QtQuick.Controls 2.12
ApplicationWindow {
id: window
width: 400
height: 400
visible: true
Button {
text: "Open"
onClicked: popup.open()
}
Popup {
id: popup
x: 100
y: 100
width: 300
height: 400
modal: true
focus: true
dim: false
contentItem: Rectangle
{
anchors.fill: parent
color: "red"
}
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
}
}
This is the output of this:
I want the red to go beyond the window borders.
Something like this:
I'd appreciate the help!
Note: using a Dialog is no good for me.
Popups are not proper windows, so you'd need to create a new window like Michael mentioned:
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
id: mainWindow
width: 640
height: 480
visible: true
ApplicationWindow {
id: redWindow
x: mainWindow.x + mainWindow.width / 2
y: mainWindow.y + mainWindow.height / 2
width: 300
height: 400
flags: Qt.Popup | Qt.Dialog
visible: true
Rectangle {
color: "red"
anchors.fill: parent
}
}
}
There is a suggestion to make Popups proper windows here.

Hide text area from SpinBox

I want to hide the text area from the spin box and show only the indicators. I am using SpinBox from QtQuick Controls 1. Example code:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 1.4
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
SpinBox {
id: spinBox
minimumValue: 37
maximumValue: 40
value: 38
stepSize: 1
}
}
Expected Output:
Is this possible?

How can I change a text in a QML from another qml?

I would like to change myText.text from the main.qml but myText is in an another folder. How can I do that?
---main.qml---
import QtQuick 2.14
import QtQuick.Window 2.1
import QtQuick.Controls 2.12
import "qrc:/secondfolder/pagetwo.qml" as PageTwo
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Button {
id: button
x: 63
y: 71
width: 142
height: 66
text: qsTr("Button")
MouseArea{
anchors.fill: parent
onClicked: {
PageTwo.myText.text = "hello world"
}
}
}
}
---pagetwo.qml---
Item {
Text {
id: myText
text: "default text"
}
}
When I run the code I got this error: "qrc:/secondfolder/pagetwo.qml": no such directory
You need to declare your PageTwo in main.qml and give it id, like this:
PageTwo {
id: pageTwo
}
Instend of PageTwo.myText.text = "hello world" you need to write pageTwo.myText.text = "hello world".
Then in file PageTwo.qml you have to write property alias myText: myText.
main.qml
import QtQuick 2.14
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
PageTwo {
id: pageTwo
}
Button {
id: button
width: 142
height: 66
text: qsTr("Button")
onClicked: {
pageTwo.myText.text = "hello world"
}
}
}
PageTwo
import QtQuick 2.14
Item {
property alias myText: myText
Text {
id: myText
text: "default text"
}
}
I'd recomend you to read this and check some qml example applications.

How change circular progress bar in QML Dial?

I have a problem with changing progress bar color in QML Dial Component. I tried to use Canvas but finally i did nothing. Any suggestions or examples?
Dial {
value: 0.5
anchors.horizontalCenter: parent.horizontalCenter
}
black progress bar
As indicated in this another answer you can use palette, for this you can check the source code, so the solution is:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Dial {
// #disable-check M17
palette.dark: "red"
value: .5
anchors.centerIn: parent
}
}
Another way to change the color of an Item is ColorOverlay, which has RGBA support.
https://doc.qt.io/qt-5/qml-qtgraphicaleffects-coloroverlay.html#details
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
import QtGraphicalEffects 1.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Dial {
id: dial
value: .5
anchors.centerIn: parent
}
ColorOverlay {
anchors.fill: dial
source: dial
color: "#80800000"
}
}

Creating a modal dialog

I created an empty Qt Quick Application, created a dialog and set the modal to "true", but it's not modal and the dialog disappears when the user clicks outside the dialog
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Component.onCompleted: pickList.open()
Dialog{
id: pickList
modal: true
width: 400
height: 400
}
}

Resources