How to show a list in a QTableWidgetItem item?
-
I have a
QTableWidgetwith 2 columns:nameandyear of birth. The user will input its name, but I would like to show a list of years inyear of birthcolumn, 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?
Thanks!
-
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.
-
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::setWidgetinstead ofQTableWidget::setItemto set aQComboBoxin the cell, and it worked fine:QComboBox* _list = new QComboBox(); _list->addItem("A"); _list->addItem("B"); _list->addItem("C"); ui->tblPks->setCellWidget(_row, 4, (QWidget*)_list);