Search code examples
pyqtqt4pyqt4qt5pyqt5

How to enable multipleselection in qtreeview till ctrl key is pressed in pyqt5?


I have a qtreeview, in which i want to enable mulitple row selection only when ctrl key is pressed . For multiple row selection i was using setSelectionMode(QAbstractItemView.MultiSelection) But found out that it looks odd means if i simply clicked a item it get selected. I don't want that. I want to select multiple rows selection only when ctrl is pressed.


Solution

  • Use ExtendedSelection rather than Multiselection.

    tree.setSelectionMode(QAbstractItemView.ExtendedSelection)