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

Add divider and background features to TableView

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • None

    Description

      As of now when we want a divider between rows and columns or a background color on a row or column we have to implement that in each cell delegate.

      On top of the poor usability in the code, it doesn't seem optimized.

      For example if we have a 100 rows 10 columns table where we want to have alternating row color we will end up with 100 * 10 / 2 (assuming no background for every other row) = 500 Rectangles.
      If that feature was added in TableView it could be brought down to 50 Rectangles (one for every other row).
      The same can be said for divider/grids between rows/columns.

      It would also improve the API:
      Current:

      delegate: Label {
          text: model.display
          background: Rectangle { visible: row % 2 === 1; color:  "lightgray" } // couldn't figure out how to do a null background so I guess that bumps up the number of background Rectangles to 1000
      }
      

      Potential future implementation:

      delegate: Label {
          text: model.display
      }
      rowBackgroundDelegate: Rectangle { visible: row % 2 === 1; color:  "lightgray" }
      

      For dividers the current code is more cumbersome:

      delegate: Label {
          text: model.display
          Rectangle { height: 1; width: parent.width; anchors.bottom: parent.bottom; color: "lightgray" }
      }
      

      And what if I don't want to show a divider on the last row? Should I query the row count in the cell delegate and conditionally hide the divider? That seems like a complex binding.

      Things get even more complicated when you want to provide a reusable component based on TableView. Moving those out of the cell delegate and providing it as a base TableView support would greatly help.
      One could easily add a pair of rowBackgroundColor and alternatingRowBackgroundColor there and define the rowBackgroundDelegate based on those if we want to keep the TableView API as simple as possible.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            grecko Pierre-Yves Siret
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes