PDA

View Full Version : QComboBox styling



Oleg
25th November 2007, 23:13
Hi, everyone.
So, recently I got a problem. I can't find the way to make every QComboBox item has its own style. It's possible to change styles for the whole widget, but not for separate items. If anyboby knows a solution, please help me.
I need something like this one http://www.innovasys.com/products/comboplus/overview.aspx.
Even simplier, I only need to change color of item's text, its background and select different font styles (bold, italic, etc).

jacek
25th November 2007, 23:15
You can make a custom model and use it instead of default QComboBox model.

Oleg
25th November 2007, 23:23
Thanks, but is there any other variants? I think it'll take a lot of time to implement new model. Or maybe there are examples how to make this?

jacek
25th November 2007, 23:48
I think it'll take a lot of time to implement new model.
It only seems to be hard, but once you make your first custom model, it will be easy.


Or maybe there are examples how to make this?
You can experiment with QStandardItemModel if you don't want to subclass anything. Although in long term it might not be the best solution. The other way is to create your own custom model by subclassing QAbstractListModel (there are instructions in the docs how to do it). You will also need a custom delegate that understands rich text (AFAIR you can find one somewhere on our site).