Question

I work with a QTableView and I would like to develop an advanced selection mode. I have not managed to do it with SelectionBehavior nor with SelectionMode.

The user shall be able to pick up some cells but only if they belong to the same column:

  • VALID BEHAVIOURS:

Select an entire column is OK Select some cells in the same column is OK

  • INVALID BEHAVIOUR:

Select cells in several columns is NOT OK

The icing on the cake would be to prevent the last row (yellow one) to be selected.

Is there any solution?


EDIT - 2013/03/05

I cannot get it work:

ui->table->setSelectionBehavior(QAbstractItemView::SelectItems);
ui->table->setSelectionMode(QAbstractItemView::MultiSelection);

connect(ui->table->selectionModel(), SIGNAL(currentColumnChanged(QModelIndex,QModelIndex)), ui->table->selectionModel(), SLOT(clearSelection()));

What's wrong with this code? I also tried QAbstractItemView::ExtendedSelection and QAbstractItemView::ContiguousSelection.

Was it helpful?

Solution

Have you checked the signals from QItemSelectionModel, especially

[signal] QItemSelectionModel::currentColumnChanged

could be used to start a new selection in case the current selection would be extended to cover two columns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top