Qt: Background color on QStandardItem using StyleSheet
        Posted  
        
            by Johan
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Johan
        
        
        
        Published on 2010-04-21T15:51:44Z
        Indexed on 
            2010/04/21
            20:33 UTC
        
        
        Read the original article
        Hit count: 642
        
qt
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?
© Stack Overflow or respective owner