[SOLVED]How to style QComboBox's line edit?
-
Hi,
I want to style QComboBox's line edit using stylesheets but unfortunately I couldn't :(
How can I fix this issue?
I tried to use:
[code]QComboBox > QWidget,
QComboBox > QWidget > QWidget {
font-size: 20pt;
text-align: center;
}[/code]I tried to use this too but it didn't change the font size while it applied the alignment!
[code] ui->comboBox->lineEdit()->setAlignment(Qt::AlignHCenter);
ui->comboBox->lineEdit()->setStyleSheet("font-size: 20pt;");[/code] -
Did you get a chance to visit Qt Help "here":http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qcombobox
-
[quote author="Dheerendra" date="1404754282"]Did you get a chance to visit Qt Help "here":http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qcombobox[/quote]
Sure dude. I tried to use the following but unfortunately it didn't apply the alignment:
[code]QComboBox:editable {
font-size: 20pt;
text-align: center;
}[/code] -
Check this.
@ QComboBox box;
box.setEditable(true);
box.lineEdit()->setReadOnly(true);
box.lineEdit()->setAlignment(Qt::AlignCenter);box.addItem("pthinks.com"); box.addItem("Dheeru"); box.setStyleSheet("min-height: 2em;min-width: 10em;font: bold 20px;");@
-
I wonder why text-align: center; doesn't work from the stylesheet?!
I always prefer to user stylesheets
-
ComboBox is made up lineEdit. LineEdit itself provides flag to center the text. So internally it may not apply stylesheet to lineEdit component. You can get the lineEdit object from combobox and then try applying your stylesheet for lineEdit and I feel this is over kill.
-
Thank you guys.