Important: Please read the Qt Code of Conduct -

How to change just one item of QCombobox editable by the user

  • i have 4 items in my QCombobox,

    'Bryce king'
    'James White'
    'Russo W'
    'Custom Manager'

    so when i click on

    'Custom Manager',

    it should change to editable and i must be able to enter my own desired name.

    i have tried to achieve this behavior using Qtcreator, and in the properties, i can set it to editable but that would make all items editable instead of just 1.

  • Lifetime Qt Champion

    Editable is for all items then.
    It cant handle only one being editable as its not the design.

    The normal use case for this would be to have it nonedible and then have

    'Add Custom Manager'

    Then when you select that, it shows a QInputDialog allowing users to enter a name and press ok to have that added to the listed and selected as the current one.

    That said something like this does work ok-ish

    void MainWindow::on_comboBox_currentIndexChanged(int index)
        if (index == ui->comboBox->count()-1)

  • @mrjj Thanks So much !!

  • Lifetime Qt Champion

    Np :)
    However, for a real app, you should also consider the use case where users spell the new name
    wrong and want to delete it/edit it later to correct it.

Log in to reply