Search code examples
c++qtqtableviewqheaderview

How can I assign different selection modes?


I have default QTableView. I want to get following selection behaviour:

  1. If we selecting cells, selection will work like if we accepted SelectionMode::ContiguousSelection
  2. If we selecting rows/column by clicking on QHeaderView section, selection will work like we accepted SelectionMode::ExtendedSelection, but deselect all cells, if any were selected.

I tried set SelectionMode to headers in QTableView constructor, but it doesn't work.

Question is how can I do it properly?


Solution

  • Okay, got it. All I had to do is just make custom selection model and handle everything in there. But I had to change SelectionMode::ContiguousSelectionto SelectionMode::ExtendedSelection in my view to get meaningful indexes in my selection model.