PDA

View Full Version : QComboBox text alignment



mentalmushroom
31st January 2012, 15:36
I'd like the text inside QComboBox to be center aligned. Is that possible? I found some workaround on the web, that is a rather strange way. QSS text-align attribute seems like doesn't affect anything.

grin
31st January 2012, 21:33
QComboBox doesn't support changing text's aligment for frame natively.
For it's popup you can use setItemData(index,aligment,Qt::TextAligmentRole).
But this way don't have effect unless you dont modify combox's view - as example you can set default QListView and see effect (see code below).
I spend hour for QComboBox source code (4.6.3) - painting text deep inside style's code.

But you can define you own combobox class and redefine painting =).
But I think that this is not a good idea.

P.S. Sorry for my english =)