In PySide I have the following MainWindow definition:
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
for i in range(10):
self.view.setModel(self.model)
self.view.selectionModel().selectionChanged.connect(self._selectionChanged)
self.setCentralWidget(self.view)
def _selectionChanged(self,selected, deselected):
pass
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.view = QtGui.QListView(self)
self.model = QtGui.QStandardItemModel()
for i in range(10):
self.model.setItem(i, QtGui.QStandardItem("Item {0}".format(i)))
self.view.setModel(self.model)
self.view.selectionModel().selectionChanged.connect(self._selectionChanged)
self.setCentralWidget(self.view)
def _selectionChanged(self,selected, deselected):
pass
To copy to clipboard, switch view to plain text mode
When I try and connect the selectionChanged signal I crash python. It's the same as this SO post and the workaround suggestion of keeping the selection model around seems to work.
self.viewselectionModel = self.view.selectionModel()
self.viewselectionModel.selectionChanged.connect(self._selectionChanged)
self.viewselectionModel = self.view.selectionModel()
self.viewselectionModel.selectionChanged.connect(self._selectionChanged)
To copy to clipboard, switch view to plain text mode
But is this safe? And is this an official bug in PySide? I could not find anything in the bug report database.
_chouqud_
Bookmarks