PDA

View Full Version : How to select a cell in a QTableView



JeanC
6th February 2008, 09:57
Hello,

How do I select a cell in a QTableView?

The only thing I can find is QTableView::setSelection () but it requires a QRect.

I like to specify row and column coordinates, how is that done?

jpn
6th February 2008, 10:09
Hello,

Take a look at QItemSelectionModel which is accessible via QAbstractItemView::selectionModel().

JeanC
6th February 2008, 10:27
Thanks jpn;

However that function takes a QModelIndex as parm. And that bugger does not have a constructor to feed row and column into.



QModelIndex i; // ?
table->selectionModel()->select(i, QItemSelectionModel::Select);

jpn
6th February 2008, 10:46
QModelIndex represents a location in the model. See QAbstractItemModel::index():


QModelIndex index = table->model()->index(row, column);

JeanC
6th February 2008, 12:41
Sorry, It seems I asked the wrong question.

This function indeed selects the cell. Good to know because it wasn't obvious to me.

But I'm searching for the function to set that cell as the current, so when the arrow keys are pushed, the adjacent cell becomes the current.

jpn
6th February 2008, 12:50
Ok, then it's QAbstractItemView::setCurrentIndex() :)

JeanC
6th February 2008, 13:20
Thanks again. Great help here.