Hello,

I've written a custom delegate for QTreeView / QTreeWidget, but I'm having a bit of trouble.

My MainWindow has the following in its stylesheet :
Qt Code:
  1. background-color: #000000;
  2. alternate-background-color: #111111;
  3. }
  4. QTreeView::item:selected:active {
  5. background: #222222;
  6. }
  7. QTreeView::item:selected:!active {
  8. background: #333333;
  9. }
To copy to clipboard, switch view to plain text mode 

Without the delegate, this works fine: I get alternating row colors, and different colors for the currently selected row, depending on whether or not the widget is enabled.

In my delegate, I have a drawBackground() method that does the following:
Qt Code:
  1. QPalette::ColorGroup cg = QPalette::Disabled;
  2. if (option.state & QStyle::State_Enabled) {
  3. if (option.state & QStyle::State_Active)
  4. cg = QPalette::Normal;
  5. else
  6. cg = QPalette::Inactive;
  7. }
  8.  
  9. if (option.showDecorationSelected && (option.state & QStyle::State_Selected))
  10. painter->fillRect(background, option.palette.brush(cg, QPalette::Highlight));
  11. else
  12. painter->fillRect(background, option.palette.brush(cg, (index.row() % 2 ? QPalette::AlternateBase : QPalette::Base)));
To copy to clipboard, switch view to plain text mode 

This code works for the alternating (unselected) rows, however, the color used for the currently selected (highlighted) row is wrong. It doesn't seem to match any of the colors actually defined in my stylesheet.

Long story short, what is the correct way to access the QSS "QTreeView::item:selected:active->background" value programatically?