PDA

View Full Version : Trying to change the background of a QTreeWidget



vycke
15th April 2008, 18:49
After a lot of searching, I'm gonna ask :)

I have a QTreeWidget on a dialog. The user requirement is that the background of the tree is the same color as QPalette::Window (and the palette can change, so just modifying the palette in designer won't work). I've tried tree->setBackgroundRole(QPalette::Window) (and even foreground role)... no difference.

If I modify the items (item->setBackground(QApplication::palette().window())), the item backgrounds are right... but the tree widget w/o items is still white (base).

Using qt 4.3.2 --- and ready to tear my hair out, since this seems to function in other places, just not the tree widget.

Vycke

aamer4yu
15th April 2008, 19:00
from the docs :


QPalette::ColorRole
QPalette::Background Window This value is obsolete. Use Window instead.


also try tree->viewport()->setPallete() if the color doesnt work
also try using setAutoFillBackground() function while setting the color.

Hope this helps :)

vycke
15th April 2008, 20:44
from the docs :

also try tree->viewport()->setPallete() if the color doesnt work
also try using setAutoFillBackground() function while setting the color.

Hope this helps :)

Ok, it works with:

tree->viewport()->setBackgroundRole(QPalette::Window);

Woot! :)

Thanks,

Vycke