> On 21 Mar 2025, at 20:55, Scott Bloom <sc...@towel42.com> wrote: > > I’m trying to set the background color on a model by returning a color inside > my models::data function. > The usage flow is as follows: > • User selects a row > • Clicks and “action button” (or possibly a double click on the row) > • The action is triggered, which should cause the row to change colors, > first to a background of yellow while the core is setting up, then to green > or red once finished (depending on success or failure) > However, since the row is selected, the selected row color is always > selected rather than being over written by the QModelIndex::data value > If I hover over the row, it changes color > If I select a previous row, the row then is painted correctly. > Is there a way, to ignore the hover state or selected state for painting? > > I haven’t tried this with other types of models. > I can create a simple test case if necessary, but since this is clearly > intended behavior, there may be a known work around for this. > Thanks > Scott
Hi Scott, The selection brush does indeed have priority. How do you plan to show to the user which item is selected? Maybe you don’t need selection at all, in which case turning selections off entirely might be the way to go. The clean approach would be to subclass QItemDelegate (or QStyledItemDelegate) and to override QItemDelegate::drawBackground. Note that the default delegate doesn’t assume that it has to care about the item’s BackgroundRole value if the item is selected (so setting e.g. a semi-transparent brush for the Highlight role won’t work). Volker _______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest