Solved How to show a list in a QTableWidgetItem item?
-
I have a
QTableWidget
with 2 columns:name
andyear of birth
. The user will input its name, but I would like to show a list of years inyear 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?
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.
-
@SGaist ,
Thanks a lot for your time!
I used
QTableWidget::setWidget
instead ofQTableWidget::setItem
to set aQComboBox
in 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);