View Full Version : QPalette Coordinating

1st February 2007, 22:00
I have a requirement to make my Qt 3.3.7 project highly configurable and one requirement is to allow the user to change the background and foreground colors. I have a QSplitter which on the left contains 4 QVGroupBoxes containing QComboBoxes, QLabels, and QLineEdits and on the right side is a QTable. All of my background colors are correct and the same, including inside the menus and submenus. All the text in my menus and in my table headers are correct but the text for the items inside the QVGroupBoxes and the QVGroupBoxes' titles are black even though the rest of the text is red. However, my QComboBoxes inside my QVGroupBoxes are written with red text. Why would the QComboBoxes palettes get the changes but the rest of the objects inside the same QVGroupBoxes would not reflect these changes? I want all my objects to have the same palette as my QMainWindow so I tell the children QVGroupBoxes

mpGroupBox->setPalette( palette( ) );

I do this after setting up the palette for my mainwindow. Does anybody have any suggestions on what I need to do to get the rest of the children to obey the palettes and to get the titles of the QVGroupBoxes to change color. Again, the background colors of all the children are correct, it is just the foreground that half the children don't listen to. I have made sure to set the colors for both the Active and Inactive states thinking this was causing the problem but this did not fix all my issues, just some of them. Thanks for your help!

3rd February 2007, 22:52
You can rewrite the style and ignore the widget palette completely.

5th February 2007, 14:18
What do you mean I can rewrite the style? I had done this successfully in Qt 4 but am required to use Qt 3 for this project and was confused as to why I could get it to work in 4 but not 3. Probably one of the nice features 4 added. But can you please elaborate on how to rewrite the style? Thanks!

5th February 2007, 14:25
Implement a proxy style (http://wiki.qtcentre.org/index.php?title=Proxy_Style) and modify the palette before the actual painting routines are called. Alternatively you can go through all widgets of the application and apply the palette manualy, but it's not a good solution. In Qt4 you could simply use stylesheets instead of all that...

Please make sure the situation is really caused by Qt and not by some error in your code before applying my suggestions. Test it on the simplest code possible. The problem might be completely different than you think (you might be using wrong colour roles for instance).

16th February 2007, 19:42
I was setting the colors for the Active and Inactive states of Text and ButtonText but wasn't doing it for the Foreground part and now I make sure to add the palette to the QColorGroup::Foreground and now it works for what I need! Thanks for your help though!!!