Reputation: 5335
I have QComboBox
inside QTableWidget
. It was created like this:
QComboBox* bb = new QComboBox(this);
ui->propsWidget->setCellWidget(1, 0, bb);
for (...)
bb.addItem(...);
I need to set its index programmatically. I've tried this:
QComboBox* bb = qobject_cast<QComboBox*>(ui->propsWidget->cellWidget(1, 0));
bb->setCurrentIndex(5);
and this:
bb->setEditText("mytext"); // "mytext" is contained in bb
but the current index is not changing. How can I do that?
Upvotes: 0
Views: 268
Reputation: 1330
You need to modify this line: QComboBox* bb = new QComboBox(this);
because QTableWidget
takes the ownership of all its subcomponents. So, it must become QComboBox* bb = new QComboBox();
, and the parent will be the table on its own.
Upvotes: 1