Qt World Summit: Register Today!

How to show a list in a QTableWidgetItem item?

  • I have a QTableWidget with 2 columns: name and year of birth. The user will input its name, but I would like to show a list of years in year of birth column, so that he/she could select from it.

    I probably did not search correctly, as I could not find any explanation or example.

    Could anyone provide an example/link of how can I do it?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can make a custom QStyledItemDelegate and in the createEditor method create a QComboBox containing the list of dates you want.

  • @SGaist ,

    Thanks a lot for your time!

    I used QTableWidget::setWidget instead of QTableWidget::setItem to set a QComboBox in the cell, and it worked fine:

          QComboBox* _list = new QComboBox();
          ui->tblPks->setCellWidget(_row, 4, (QWidget*)_list);


Log in to reply