I'm working on a little system of message dialog windows in QML. For this I'm using a container with a Loader to load the different messages (these are not just text but text and graphical symbols layouted hence loading a QML file for each individual message). By default these message windows have the same size, so I have my size information directly in the container. But some messages can be longer, therefore I'm looking for a way to use the height of my loaded component if it exceeds the default value.
The way I see it my problem can be split into three parts:
Loader object?Any suggestions?
You can access loaded object using item keyword.
Example if your loader id is idLoader, then the created item is idLoader.item, you have 2 solutions to do what you want:
1:How to access the size information of the loaded component through my loader object?
Loader{
id:idLoader
width: (item !== null && typeof(item)!== 'undefined')? item.width : 0
height: (item !== null && typeof(item)!== 'undefined')? item.height: 0
}
2: How to have a container sized by the dimensions of its children? & How to selectivly use the larger size?
Loader{
id:idLoader
width: childrenRect.width
height : childrenRect.height
}
Here's an idea, untested. Take the max of the child's preferred height or a hard-coded minimum, whichever is larger.
Loader {
height: Math.max(item ? item.implicitHeight : 0, 200)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With