Seems like it's not so straigthforward as one could imagine..
#include <QtGui>
int main(int argc, char *argv[])
{
// create an example combo
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();
}
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// create an example combo
QComboBox combo;
QStringList items;
for (int i = 0; i < 10; ++i)
items << QString::number(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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks