How to get widget within cell of QTableWidget to pass focus to the QTableWidget?



  • 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



  • 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?



  • 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.



  • 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).



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.