如何在 qtreeview 中启用多选直到在 pyqt5 中按下 ctrl 键?

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

我有一个 qtreeview,其中我只想在按下 ctrl 键时启用多行 selection。 对于多行 selection,我使用的是 setSelectionMode(QAbstractItemView.MultiSelection) 但发现它看起来很奇怪意味着如果我简单地单击一个项目它就会得到 selected。我不想要那个。我只想在按下 ctrl 时 select 多行 selection。

使用 ExtendedSelection 而不是 Multiselection。

tree.setSelectionMode(QAbstractItemView.ExtendedSelection)