Important: Please read the Qt Code of Conduct -

How to set CurrentText of QComboBox?

  • I want to set the text of this widget when no item selected yet. At the beginning my comboBox is empty, then in runtime program adds elements to this box, and i want instantly display in comboBox some string("Elemens inside"+QString::number(i)). But i can't find proper function.





    is not working, i don't know why...

    P.S. i dont need change text of first item, i need only set initial text of the header of that box.

  • @Engelard
    You want to set the text in an editable QComboBox's QLineEdit widget to some string, right? In what way does ui->comboBox->setCurrentText(QString::number(i)); not work? Please be precise.

  • Moderators

    is your Combobox editable? if not, setCurrentText will have no effect

    The setter setCurrentText() simply calls setEditText() if the combo box is editable. Otherwise, if there is a matching text in the list, currentIndex is set to the corresponding index.

Log in to reply