timing of sizing calculations
-
Hi all -
I've got some code that looks like this:
ListModel { id: settingsModel ListElement { rowName: "LAN Connection"; rowIcon: "qrc:/icons/Display.svg" } ListElement { rowName: "WAN Connection"; rowIcon: "qrc:/icons/DateTime.svg" } ListElement { rowName: "Server"; rowIcon: "qrc:/icons/Temp.svg" } ListElement { rowName: "Site Connection"; rowIcon: "qrc:/icons/DisplaySettings.svg" } } ListView { id: networkSettingsListView Component.onCompleted: console.log("networkSettingsListView.width", width) delegate: DelegateChooser { model: settingsModel role: "rowName" DelegateChoice { roleValue: "LAN Connection" delegate: networkDelegate } } } Component { id: networkDelegate Pane { id: networkDelegatePane Component.onCompleted: console.log("networkDelegatePane.width", width) width: networkSettingsListView.width ...
At runtime, I get this:
debug:qml:expression for onCompleted: networkDelegatePane.width 0. debug:qml:expression for onCompleted: networkSettingsListView.width 512.
I need the correct width value in my component, as I use it to size items within the component. Is there some way to get this to happen automatically?
Thanks...
-
The
width: networkSettingsListView.width
should be enough.
Provide a minimal reproducible example. The ListView has no width set in the code you pasted. -
Use declarative bindings and don't rely on
Component.onCompleted
. -
hi @GrecKo - the Component.onCompleted is strictly for logging; I'm not trying to do any resizing with it.
When you say "use declarative bindings," do you mean something more than what I'm doing here?
Pane { id: networkDelegatePane Component.onCompleted: console.log("networkDelegatePane.width", width) width: networkSettingsListView.width
Thanks...
-
The
width: networkSettingsListView.width
should be enough.
Provide a minimal reproducible example. The ListView has no width set in the code you pasted. -
@GrecKo said in timing of sizing calculations:
The ListView has no width set in the code you pasted.
Right you are. I added explicit width to the ListView, and it now seems to size properly. I guess the console logs I put in were a bit misleading. Thanks!
-
M mzimmers has marked this topic as solved on