fyngyrz fyngyrz - 4 months ago 51
C++ Question

qt QTableWidget programattic select of cell - how to make ready with cursor in?


  • Qt 4.7.1

  • Qt Creator 2.1.0

  • c++


I have a QTableWidget. I add a row, and then select the first cell.

What I want is to be able to immediately type into the cell after the program selects it, so I don't have to reach for the mouse.

The behavior of the select is to highlight the cell, not put a cursor in it. I have to click on the cell with the mouse before I can type.

Everything I've found so far to do with selection behavior has to do with row, column, or cell selection options; nothing about what the selection of a cell actually does.

Here's my code thus far, works as described;
is the index to the last row, already determined:

QModelIndex index = ui->thetable->model()->index(rc, 0);


You can use the edit method this way:


using the index you already computed, or you could connect a custom signal of yours to void QAbstractItemView::edit ( const QModelIndex & index ) slot inherited by QTableWidget's items.