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

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

    XMLWordPrintable

Details

    • 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.

      Attachments

        1. GridView-missing-cell.png
          4 kB
          Chris Dolan
        2. GridViewScrolling.qml
          2 kB
          Chris Dolan
        3. GridViewScrolling.qmlproject
          0.4 kB
          Chris Dolan
        For Gerrit Dashboard: QTBUG-49218
        # Subject Branch Project Status CR V

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes