Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-49218

Off-by-one drawing bug in GridView on model change

XMLWordPrintable

    • ddf495fb81ea89173af3310f50314b177bc866d2

      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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            smd Jan Arve
            chrisdolan Chris Dolan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes