QTableView Multi-Selection
-
Hello,
I'm just getting started on handling multi-selection in a Pyside6 QTableView. I'm still learning the concepts and how it can work.
Can someone give high-level advice on what needs to be done? I haven't found an example in this forum yet nor on the internet.I am working with PySide6, I should be able to follow C++ advice.
I see that the QTableView object derives from QAbstractItemView which has a state that can be queried.
I think that tracking the state for cell clicked and cell entered will be needed.
The state is equal to NoState for the first cell entered.
The state is equal to NoState for the first cell clicked.
I observe that the entered slot is called first then the clicked slot. That seems obvious, is the order guaranteed?
If you hold the shift key and drag the mouse then the cells you drag into will have the DragSelectingState.- So for multi-selection I may need to track/record that first cell in the clicked slot handler and then when entered is called with state = DragSelectingState,
see if the very first cell clicked is one cell before the first dragged into cell. - Put another way, in the entered slot handler if DragSelectingState is True then an adjacent cell must have been entered with a mouse click.
And that adjacent cell needed to be tracked/recorded so that the cells dragged into can determine the first cell.
I have set these properties on the table_view (QTableView) object:
table_view.setSelectionMode(QAbstractItemView.ExtendedSelection)
table_view.SelectionBehavior(QAbstractItemView.SelectRows)
table_view.setMouseTracking(True)I've made these signal-slot connections:
table_view.clicked.connect(self.func_table_view_cell_clicked)
table_view.entered.connect(self._cell_entered)Am I grasping the key concepts correctly?
Does anyone have any sample code that I can refer to?Thanks for any help that you can provide,
Richard - So for multi-selection I may need to track/record that first cell in the clicked slot handler and then when entered is called with state = DragSelectingState,
-
Hi and welcome to devnet,
Wouldn't QItemSelectionModel cover your needs ?