QComboBox addin dummy placeholder
Solved
General and Desktop
-
Hi all,
I have been searching for a while, a way to add dummy item into my combo box but without any luck. I have an combo box and I would like to add a place holder text like "Select Year" as a default first item. Does anyone have any examples of this?
Tnx
-
Hi
You can try
ui->comboBox->setEditable(true);
ui->comboBox->setCurrentIndex(-1);
ui->comboBox->setCurrentText("DUMMY TEXT");it will then show dummy text until user selects something.
-
Hi
ok super. make sure to also try @A.A.SEZEN suggestions
ui->comboBox->setEditable(true);
ui->comboBox->lineEdit()->setPlaceholderText("Text");
as thats a real text place holder :) -
Hi
Depending on platform. this might workQPalette pal = ui->lineEdit->palette(); pal.setColor(QPalette::ColorRole::PlaceholderText, QColor( 255,0,0)); ui->lineEdit->setPalette(pal);
Does on Win 10. Not tested anything else.
-
worked for me:
self.name_dropdown.placeholderText() self.name_dropdown.setPlaceholderText('Choose Operator') self.name_dropdown.addItems(['Name1, 'Name2', 'Name3'])