0

I wanted to center align text items in a QComboBox but to do this I need to set Editable to true. When I do this the look changes significantly. This is on Windows 7.

QComboBox when setEditable(false)

QComboBox when setEditable(true)

I think the change happens because QLineEdit has a different default appearance than QComboBox. What can I do to get them both to look the same? Thanks,

1 Answers1

0

When you enable the editable state of the QComboBox the default widget change to a QEditText so you have to edit the QEditText style using Qt Style Sheet:

QLineEdit* lineEdit = new QLineEdit(parent);
lineEdit->setStyleSheet("here customize");
lineEdit->setAlignment(Qt::AlignCenter)
ui->combo->setLineEdit(lineEdit);

If you want no editable line edit, try this:

lineEdit->setReadOnly(true);
ui->combo->setLineEdit(lineEdit);
ui->combo->setEditable(true);

An alternative, you can customize your own QComboBox and modify the paintEvent(...).

mohabouje
  • 3,867
  • 2
  • 14
  • 28
  • Thank you. I kind of figured that but I am at a loss as to how to figure out the default style settings for the un-editable QComboBox so I can apply them to the editable QComboBox. I did set the read-only true but it still gave me the different look. – Bob Ritchey Sep 06 '16 at 15:57