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

QStyledItemDelegate::initStyleOption fills in option even with an invalid index

    XMLWordPrintable

Details

    Description

      Since the introduction of QModelRoleDataSpan, QStyledItemDelegate reuses the same span for each call to initStyleOption. (Strictly, a new span, but using a pointer to the same std::array of QModelRoleData.) Calling it with a valid index fills in the values in the span, and from there fills in the QStyleOptionViewItem passed in. Calling it a second time, this time with an invalid index, skips the step that fills in the span. But it still fills in the style option, with the existing values stored in the span, i.e. the ones for the most recent valid index.

      This leads to some slightly odd bugs if you are trying to do some funky stuff with reusing some of the paint code for e.g. painting a background, by passing in a valid option missing the text and icon, and an invalid index (which is what I was attempting and worked on Qt5).

      The attached file reproduces the issue. I'd expect the output to be:

      Valid index: "One"
      Invalid index: ""
      Different invalid index: ""
      

      Instead it gives:

      Valid index: "One"
      Invalid index: "One"
      Different invalid index: "One"
      

      Attachments

        1. main.cpp
          1 kB
          Arthur Gordon-Wright
        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
            arthurgw Arthur Gordon-Wright
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes