PDA

View Full Version : QTableView disable multiselect while retain row select mode



MarkoSan
7th August 2014, 11:47
Dear Sirs and Madams!

Is it possible to disable cell multiselect in QHeaderView while retaining row select mode and if it is, how? If it is not, are there some ideas how to at least try to achieve something similar?

Sincerely,
Marko

Rajesh.Rathod
7th August 2014, 13:00
Please read about QAbstractItemView::SelectRows, it will solve your problem.

MarkoSan
17th August 2014, 12:05
Please read about QAbstractItemView::SelectRows, it will solve your problem.Yes, but now I cannot select a single cell. I have following situation:

I have a matrix of digital inputs and digital outputs. The matrix itself is subclassed QTableView, which has two subclassed QHeaderViews, vertical one for digital inputs and horizontal one for digital outputs. Now, if I click on single cell in matrix, I connect signal (electrical, not Qt one) with indexed input and ouput. If I select row, I connect one input to all outputs. And I MUST disable the option of column select, since connecting all digital inputs to one digital ouput present a problem, the user MUST not be able to do that. I've managed to disable column selection, but I cannot enforce the option of selection of single cell and if user prefers, to connect one input to all ouputs - row selection mode. How do I do that?

Sincerely,
Marko

d_stranz
19th August 2014, 22:13
Yes, but now I cannot select a single cell.

In this case, leave the selection mode for the table set to single cell selection. That will accomplish the 1 <-> 1 connection mode. Then, connect a slot to the row header's QHeaderView::sectionClicked() signal. In your slot, manually select all of the cells in the row. Do this by retrieving the selection model for the table (QTableView::selectionModel()), then create a QItemSelection that contains QModelIndex entries for all of the cells in the row, and finally calling QItemSelectionModel::select() with this QItemSelection. Calling select() will result in the selectionChanged() signal being emitted by the QItemSelectionModel, so you should be able to use the same slot to handle this as you do the single cell select.

Note that you can't simply call QTableView::selectRow() because your selection mode allows only single cell selection.