[SOLVED] Changing the color of a QListWidget
-
Hi,
I'm trying to change the color(s) of the selected item from the default blue and light grey to a predefined rgb color and seem to be having a bit of a problem. I'm using the folowing code.
@
...
p.setColor(QPalette::Base, QColor(0,0,0)); // Black Background
p.setColor(QPalette::Text, QColor(r, g, b)) // Color of text;
p.setColor(QPalette::Highlight, QColor(r, g, b));
setPalette(p);
@The background gets set to black, the text to the proper color, but the bar is still blue focused and grey not focused. I would prefer to use the palette instead of style sheets if possible.
Thanks in advance...
-
The "documentation":http://qt-project.org/doc/qt-4.8/qwidget.html#palette-prop for setPalette says the palette may be ignored on certain platforms. It implies that stylesheets will work.
-
As ScottR said selection style is actually very platform dependent. Eg. on Windows it doesn't use palette because it adds some highlights and gradients .
You can override this in stylesheet, but it's good to keep all color management in one place, so an easy fix would be to force the ui to use palette for selection:
@
ui->listWidget->setStyleSheet("QListView::item:selected { background: palette(Highlight) }");
@
Then you can control the actual color via palette with all the other colors. -
Thanks for the replies, really appreciate them, the second one however does not work as well.
Thanks
-
Hi guys,
Thanks for all the help, I took a different approach to it and decided to utilize the style sheets while maintaining control over custom colors. Works like a champ..
Thanks again for all your help.