can entries in a combobox be aligned right or centered?
thanks!
lou
Printable View
can entries in a combobox be aligned right or centered?
thanks!
lou
Seems like it's not so straigthforward as one could imagine.. :)
Code:
#include <QtGui> int main(int argc, char *argv[]) { // create an example combo QComboBox combo; QStringList items; for (int i = 0; i < 10; ++i) combo.addItems(items); // align the line edit combo.setEditable(true); combo.lineEdit()->setAlignment(Qt::AlignHCenter); // combo.lineEdit()->setReadOnly(true); // align items for (int i = 0; i < combo.count(); ++i) { combo.setItemData(i, Qt::AlignHCenter, Qt::TextAlignmentRole); } combo.show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec(); }
thank you very much, just what i need!
thanks!
lou
Hi,
I have a similar problem, but with a non editable combobox. The list of items is correclty centered, but since there is no lineEdit in a non editable combo box, I can't recenter the currently selected item. Any idea ? Thx !
Ok, just found the solution. Like jpn posted above, you _must_ have your combobox configured with setEditable(true), but you then you have to disable user input by setting the lineEdit to read-only. Thx jpn !