Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.4.1
-
ddf495fb81ea89173af3310f50314b177bc866d2
Description
The QML GridView component has an off-by-one layout error under special circumstances. In the attached "GridView-missing-cell.png" screenshot, the (0,0) element is drawn in the (0,1) position, the (0,1) element in the (0,2) position, etc.
Steps:
1) run the attached GridViewScrolling project
2) scroll to the bottom of the grid
3) select the last element (the "a")
4) scroll back to the top
5) click the "switch" button
6) click the "switch" button again
I believe the bug is in this code in qquickgridview.cpp, in the addVisibleItems function:
// Find first column if (visibleItems.count()) { FxGridItemSG *firstItem = static_cast<FxGridItemSG*>(visibleItems.first()); rowPos = firstItem->rowPos(); colNum = qFloor((firstItem->colPos()+colSize()/2) / colSize()); if (--colNum < 0) { colNum = columns - 1; rowPos -= rowSize(); } } else { colNum = qFloor((colPos+colSize()/2) / colSize()); }
In the "else" branch, we should decrement the colNum just like we do in the "if" branch. My example code gets into this state because it calls positionViewAtIndex() at just the wrong moment which clears the visibleItems list.