Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.4.2
-
None
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"