PDA

View Full Version : QStandardItem background color with Stylesheets enabled



hubbobubbo
21st April 2010, 17:54
Hi

I have a class that inherits QStandardItem and I put the elements in a QTreeWidget. The class receive notifications from the outside and I want to change the background color of the item based on what happened.

If I do not use stylesheets it works just fine, like this:

void myClass::onExternalEvent() { setBackground(0, QColor(255,0,0))); }

However as soon as I put a stylesheet on the QTreeWidget this has no effect, the stylesheet seems to override the setBackground call.

So I tried : void myClass::onExternalEvent() { this->setStyleSheet("background-color: red"); }

but this is probably all wrong, it changed the color of some other element on my screen, not sure why.

So anyone have an idea on how I can alter the background color like with setBackgroundColor but still be able to use stylesheet on my QTreeWidget?

nikhilqt
22nd April 2010, 11:23
Could you give contents of your stylesheet, it will help to see what exactly it is applying to your app ?