How to get widget within cell of QTableWidget to pass focus to the QTableWidget?
-
wrote on 6 Jun 2011, 19:38 last edited by
I'm setting a cell in QTableWidget to another widget like so:
@
QSpinBox* widget = new QSpinBox();
widget->setValue(1);
widget->setRange(1, 255);
widget->setSingleStep(1);
ui->tableWidget->setCellWidget(row, col, widget);
@but when I click on that widget, the QTableWidget does not update to the current cell.
EDIT: please use @-tags for code highlighting, Gerolf
-
wrote on 6 Jun 2011, 20:38 last edited by
I'm not sure if I understood your expectations. What do you mean by "QTableWidget does not update to the current cell"?
Also, what are row and col supposed to be in your code?
-
wrote on 6 Jun 2011, 22:16 last edited by
row and col are just place holders for this example.
When I click on the spinbox, the QTableWidget does not recognize that I clicked within it. I can change the spinbox fine, but when I try to get the current cell from the TableWidget, I just get -1, which is no cell selected.
-
wrote on 7 Jun 2011, 05:49 last edited by
Sure, why should the table be changed? you did not connect the spin box with the table. If you use cell widgets, that's up to you to update the content of the table.
If not a permanent widget is needed, I suggest you use a "delegate":http://doc.qt.nokia.com/4.7/model-view-programming.html#delegate-classes . A delegate can be used to create the cell editors, once the user starts editing a cell. Those values are then stored in the corresponding data model (it's part of the QTableWidget).
-
wrote on 7 Jun 2011, 06:13 last edited by
The following "FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_get_hold_of_a_cell_widgets_row explains how you can get hold of a cell widget's row and column information. Does it provide you the information you are looking for?
1/5