0

I have a QTreeView with a QFileSystemModel and a QListView. I want only one row to be selected either in one of the views. So I need to clear the selection of the opposite view on each selection action.

I have functions for each view to clear the opposite views selection. The problem is while clearing the opposite view, I am also triggering the signal for the opposite view as well even though there is no user interaction with that view. I guess there isn't any signal to separate user interaction like the one in QCheckbox. I appreciate any help on this.

...
self.ListView.currentItemChanged.connect(self.onListViewActivated)
self.TreeView.selectionModel().currentRowChanged.connect(self.onTreeViewActivated)
def onListViewActivated(self):
    # do some stuff
    self.TreeView.setCurrentIndex(self.model.index(self.rootDirectory))
def onTreeViewActivated(self):
    # do some stuff
    self.ListView.setCurrentRow(-1)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Arda Kutlu
  • 60
  • 1
  • 7
  • Looking at [this question](https://stackoverflow.com/questions/3556687/prevent-firing-signals-in-qt) it seems like you can simply do `self.ListView.blockSignals(True)` and then `self.ListView.blockSignals(False)` when you are done. However this prevents all signals to be triggered. – Giacomo Alzetta Sep 11 '18 at 15:29
  • Alternatively,if you do not want to block all signals you could `disconnet` the slot and re-`connect` it again when you are done. – Giacomo Alzetta Sep 11 '18 at 15:35

0 Answers0