setting arguments in reused QML file
-
wrote on 4 Feb 2021, 23:52 last edited by
Hi all -
I've looked through the docs, but didn't find quite what I wanted. I have a QML file (SortedTable.qml) that is used by several displays. I need to modify it so the parent can specify the widths of the columns.
Currently, the column widths are formatted like this:
property int cellWidth: width / (viewModel.header().length + extraCols_) property real cellStretch0: cellWidth * 1.7 property real cellStretch1: cellWidth * 0.4 property real cellStretch2: cellWidth * 0.9 property real cellStretch3: cellWidth property variant columnWidths: [cellStretch0, cellStretch1, cellStretch2, cellStretch3]
And the property columnWidths is used in various places in SortedTable.
I'd like to move the cellStretchN definitions out of SortedTable, into the parent files, but have a default value for them in SortedTable. I'm sure this can be done, but I need a pointer on how.
Thanks...
-
Hi all -
I've looked through the docs, but didn't find quite what I wanted. I have a QML file (SortedTable.qml) that is used by several displays. I need to modify it so the parent can specify the widths of the columns.
Currently, the column widths are formatted like this:
property int cellWidth: width / (viewModel.header().length + extraCols_) property real cellStretch0: cellWidth * 1.7 property real cellStretch1: cellWidth * 0.4 property real cellStretch2: cellWidth * 0.9 property real cellStretch3: cellWidth property variant columnWidths: [cellStretch0, cellStretch1, cellStretch2, cellStretch3]
And the property columnWidths is used in various places in SortedTable.
I'd like to move the cellStretchN definitions out of SortedTable, into the parent files, but have a default value for them in SortedTable. I'm sure this can be done, but I need a pointer on how.
Thanks...
wrote on 5 Feb 2021, 00:10 last edited by ODБOï 2 May 2021, 00:10hi @mzimmers
If i understand the question correctly, there is nothig special to do here, you can let whatever default value in Sorted Table.qml and then reassign that value when you create SortedTable components -
hi @mzimmers
If i understand the question correctly, there is nothig special to do here, you can let whatever default value in Sorted Table.qml and then reassign that value when you create SortedTable componentswrote on 5 Feb 2021, 00:16 last edited by@LeLev here's what I tried:
SortedTable.qml:
Item { id: root property int cellWidth: width / (viewModel.header().length + extraCols_) property real cellStretch0: cellWidth property real cellStretch1: cellWidth property real cellStretch2: cellWidth property real cellStretch3: cellWidth
and in the parent:
SortedTable { property real cellStretch0: cellWidth * 1.7 property real cellStretch1: cellWidth * 0.4 property real cellStretch2: cellWidth * 0.9 property real cellStretch3: cellWidth
but it doesn't "take" (the values in the parent aren't used).
-
@LeLev here's what I tried:
SortedTable.qml:
Item { id: root property int cellWidth: width / (viewModel.header().length + extraCols_) property real cellStretch0: cellWidth property real cellStretch1: cellWidth property real cellStretch2: cellWidth property real cellStretch3: cellWidth
and in the parent:
SortedTable { property real cellStretch0: cellWidth * 1.7 property real cellStretch1: cellWidth * 0.4 property real cellStretch2: cellWidth * 0.9 property real cellStretch3: cellWidth
but it doesn't "take" (the values in the parent aren't used).
wrote on 5 Feb 2021, 00:20 last edited by ODБOï 2 May 2021, 00:21@mzimmers said in setting arguments in reused QML file:
SortedTable {
property real cellStretch0: cellWidth * 1.7you are re-declaring the properties, you just need to assing the new values like this
SortedTable { cellStretch0: cellWidth * 1.7 cellStretch1: cellWidth * 0.4
but i'm not sure columnWidths will be updated in the component, you might need to reassign it
-
@mzimmers said in setting arguments in reused QML file:
SortedTable {
property real cellStretch0: cellWidth * 1.7you are re-declaring the properties, you just need to assing the new values like this
SortedTable { cellStretch0: cellWidth * 1.7 cellStretch1: cellWidth * 0.4
but i'm not sure columnWidths will be updated in the component, you might need to reassign it
wrote on 5 Feb 2021, 16:19 last edited by@LeLev thank you! This works fine. And the array does indeed update -- I guess it's created on-the-fly when the screen is invoked.
Thanks again for the help.
-
@LeLev thank you! This works fine. And the array does indeed update -- I guess it's created on-the-fly when the screen is invoked.
Thanks again for the help.
wrote on 5 Feb 2021, 17:09 last edited by ODБOï 2 May 2021, 17:28@mzimmers You're welcome :)
BTW "variant" qml type is obsolete. If possible, you should use "var" instead
see here https://doc.qt.io/qt-5/qml-variant.html
1/6