PDA

View Full Version : Qt custom Palette



bunjee
22nd January 2009, 18:19
Hey trolltechers,

Is it possible to subclass QPalette and create customs QPalette colors?

Thanks.

wysota
23rd January 2009, 00:22
You don't have to subclass anything. Just use QPalette::setColor() (or similar) to set colours for different uses. Subclassing QPalette wouldn't make much sense - it doesn't contain any virtual methods.

bunjee
23rd January 2009, 09:56
I cannot create new "QPalette::ColorRole" then.

wysota
23rd January 2009, 22:46
You don't create colour roles, you assign colours to them.


QPalette palette;
palette.setColor(QPalette::WindowText, Qt::red);

Creating new colour roles wouldn't make much sense as Qt widgets wouldn't use them anyway. If you want custom roles for your widgets only, you can subclass QPalette or use a separate object for storing them, only remember you'll have to take care of properly initializing and handling the "palette" at every step.