Dialog gets not resized with loader
-
Hello,
I have a dialog,where I load depending on the input of a combo box different QML files with different size, but always some layout.
The problem is, whenever I select the item in the combo box, the qml file will be loaded but only the first line will be showed, the dialog does not resize properly, when I manually resize it, the content of the qml file is displayed properly.
How can I tell the Layout to resize or redraw? I have not found a LayChanged signal in the documentation or something similar
Dialog{ ListModel{ id: comboBoxModel ListElement{ name: "First" path: "first.qml" } ListElement{ name: "Second" path: "second.qml" } } ColumnLayout{ anchors.fill: parent GridLayout{ Layout.fillWidth: true columns: 2 Label{ text: "Selection" } ComboBox{ model: comboBoxModel textRole: "name" valueRole: "path" onCurrentIndexChanged: { if (currentIndex > 0) { console.log( currentText, currentValue ) loader.setSource( currentValue, {} ) } } } } Loader{ id: loader Layout.fillWidth: true asynchronous: true visible: status == Loader.Ready onStatusChanged: { if (status == Loader.Ready){ loader.item.visible = true } } } } }
-
I suspect width & height of the loader are the issue. Try to set some size or bind the values to loaded item.
-
I suspect width & height of the loader are the issue. Try to set some size or bind the values to loaded item.
@dheerendra
How to set the height of the loader properly accordingly to it's item?Normally the Dialog should resize, right?
-
@dheerendra
How to set the height of the loader properly accordingly to it's item?Normally the Dialog should resize, right?
Try some thing like this for loader
```
height: loader.item != null ? loader.item.height : 0
width: loader.item != null ? loader.item.width : 0
Layout.fillWidth: true -
Try some thing like this for loader
```
height: loader.item != null ? loader.item.height : 0
width: loader.item != null ? loader.item.width : 0
Layout.fillWidth: trueWhen I try to print the values I get 0 for both
Loader{ id: loader Layout.fillWidth: true asynchronous: true visible: status == Loader.Ready onStatusChanged: { if (status == Loader.Ready){ loader.item.visible = true console.log( loader.item.height ) console.log( loader.item.width ) } } }
qml: 0 qml: 0
When i change the height to something:
Loader{ id: loader Layout.fillWidth: true asynchronous: true visible: status == Loader.Ready height: loader.item != null ? loader.item.height : 100 onStatusChanged: { if (status == Loader.Ready){ loader.item.visible = true //console.log( loader.item.height ) //console.log( loader.item.width ) } } onHeightChanged: console.log( "Loader", height ) }
I get the following:
qml: Loader 100
-
Try some thing like this for loader
```
height: loader.item != null ? loader.item.height : 0
width: loader.item != null ? loader.item.width : 0
Layout.fillWidth: true@dheerendra
The problem was the loaded QML, I was using a "anchors.fill: parent"Now I get always get 101, but don't know why, is this a default?
Loaded QML:
import QtQuick import QtQuick.Controls import QtQuick.Controls.Material import QtQuick.Layouts import Qt.labs.settings Item{ id: csvRecordImport implicitHeight: gl.height Settings { id: settings } Component.onCompleted: { delimiter.currentIndex = settings.value("ui/importRecordDialog/csv/delimiter", 0) csvHeader.checkState = settings.value("ui/importRecordDialog/csv/csvHeader", Qt.Unchecked) } Component.onDestruction: { settings.setValue("ui/importRecordDialog/csv/delimiter", delimiter.currentIndex) settings.setValue("ui/importRecordDialog/csv/csvHeader", csvHeader.checkState) } signal updated() function getParameters() { var parameter = {} parameter["delimiter"] = delimiter.currentValue parameter["header"] = csvHeader.checked var json_str = JSON.stringify(parameter) return json_str } GridLayout{ id: gl columns: 2 Label{ text: qsTr("Delimiter:") } ComboBox{ id: delimiter Layout.fillWidth: true textRole: "text" valueRole: "value" onCurrentValueChanged: csvRecordImport.updated() model: ListModel{ ListElement{ text: qsTr("Comma (Default)"); value: "," } ListElement{ text: qsTr("Semicolon"); value: ";" } ListElement{ text: qsTr("Tab"); value: "\t" } } } CheckBox{ id: csvHeader text: qsTr("CSV Header") onCheckStateChanged: csvRecordImport.updated() } } }
Loader{ id: loader Layout.fillWidth: true asynchronous: true visible: status == Loader.Ready //height: loader.item != null ? loader.item.height : 100 onStatusChanged: { if (status == Loader.Ready){ loader.item.visible = true //console.log( loader.item.height ) //console.log( loader.item.width ) } } onHeightChanged: console.log( "Loader", height ) } Connections { target: loader.item function onUpdated() { openFile( filePath.text ) } function onHeightChanged() { console.log( "Item", height ) } }
When I use the implicitHeight of the I get:
qml: Loader 101
But I see all of the item including a lot of free space
With height I get:
qml: Loader 101 qml: Item 429 qml: Loader 0
-
R Rusticus has marked this topic as solved on