문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top