QML Grid: Grid contains more visible items than rows*columns
-
Hi,
i am using a square Grid, which dimension (row&column count) is being set by the user via a SpinBox.
See screenshot below.When I decrease the dimension (e.g. 6 down to 5), i recieve two warnings:
QML Grid: Grid contains more visible items (36) than rows*columns (30) QML Grid: Grid contains more visible items (30) than rows*columns (25)
This does not happen when increasing the dimension.
Here's the relevant code part:Grid { id: myGrid property int dimension: Controller ? Controller.dimension : 0 rows: dimension columns: dimension Repeater { model: myGrid.columns * myGrid.rows Rectangle { //... } } }
In this version the local property dimension is retrieved from a Q_PROPERTY in my c++ Controller.
_I have then tried changing the Grid's model to access the Q_PROPERTY directly:
model: Controller.dimension * Controller.dimension
Now I recieve a (here: single!) warning when increasing (here: 5 up to 6) the dimension:
QML Grid: Grid contains more visible items (36) than rows*columns (30)
In this version, I don't get a warning when decreasing the dimension, so almost the other way round.
_As a third shot, I have simplified the code into directly referencing the SpinBox - the same happens:
Grid { id: myGrid rows: mySpinBox.value columns: mySpinBox.value Repeater { model: mySpinBox.value * mySpinBox.value Rectangle { //... } } }
I can't see, what I am doing wrong...
How can I coerce the Grid into getting its act together before issuing a warning? -
What if you remove
rows: dimension
from your Grid?
This way the number of children will not be constrained and your delegates will still be correctly positioned since only thecolumns
number is used in a left to right flow. -
I think you misunderstand what you are increasing here: you're increasing the model size, ie, the number of elements in the array, if you will. Your grid can contain 5*5 elements, but when you increase your model size (with the spin box), you get the warning.
-
What if you remove
rows: dimension
from your Grid?
This way the number of children will not be constrained and your delegates will still be correctly positioned since only thecolumns
number is used in a left to right flow. -
What if you remove
rows: dimension
from your Grid?
This way the number of children will not be constrained and your delegates will still be correctly positioned since only thecolumns
number is used in a left to right flow.@GrecKo looking at his code more closely, I wonder if he's experiencing a bit of a race condition. In one of his examples, both the grid dimensions and the model size are set from the SpinBox. If he increases the SpinBox, and the model is updated before the dimensions, he'd get an error. Similarly if he decreases the SpinBox, and the dimensions are updated first, he'd also get an error.
-
Yes that's what I assumed. My guess is that the warnings are just sanity checks enabled when both columns and rows are set, but failing the check has no actual impact. Dues to the non-deterministic binding order evaluation the number of children and grid cells are not synchronized like you explained.
-
S SeDi has marked this topic as solved on
-
Thanks to you both!
Removingrows: Controller ? Controller.dimension : 0
did the trick.
It's like parenting: sometimes you just have to trust without setting redundant constraints.@SeDi said in QML Grid: Grid contains more visible items than rows*columns:
It's like parenting: sometimes you just have to trust without setting redundant constraints.
That's actually a very good insight - when you use Layouts in QML, you're giving QML permission to handle some things on its own, without as much specific direction from the programmer. They take some getting used to, but they can offer a lot in return.