Only QObjects can emit signals. If you want to get notification when the selected item(s) changes, then you need to connect to the view's selection model: http://doc.qt.io/qt-5/qabstractitemview.html#selectionModel
I don't see any reason why C++ should be different from python on this topic. Chris On 4 August 2016 at 16:31, Frank Rueter | OHUfx <[email protected]> wrote: > Hi, > > I am writing a custom view for a simple data model and need to have a > custom widget change it's background colour when it's associated > QStandardItem has a certain attribute. > I thought I'd simply subclass QStandardItem, give it the custom attribute, > e.g. isSelected, then a method called setSelected() which sets the > attribute's value and emits a selectionChanged signal, to which I can > connect the associated widget's slot that changes the background colour. > So this is what I have for the item: > > class ElemItem(QtGui.QStandardItem): > selectionChanged = QtCore.Signal(bool) > > def __init__(self, elementData): > super(ElemItem, self).__init__(elementData) > self.isSelected = False > self.filePath = elementData > > def setSelected(self, selected): > self.isSelected = selected > selectionChanged.emit(selected) > > > However, since QStandardItem doesn't inherit QObject it doesn't seem to be > able to emit a signal. When I try something like this in the widget: > self.item.selectionChanged.connect(self.markAsSelected) > > I get this error: > AttributeError: 'PySide.QtCore.Signal' object has no attribute > 'connect' > > > Is this the entirely wrong way of achieving what I'm after? > I can achieve what I'm after in other ways but would like to understand > this hiccup before moving on, so any input would be welcome. > > Cheers, > frank > > > > -- > [image: ohufxLogo 50x50] <http://www.ohufx.com> *vfx compositing > <http://ohufx.com/index.php/vfx-compositing> | workflow customisation and > consulting <http://ohufx.com/index.php/vfx-customising> * > > _______________________________________________ > PySide mailing list > [email protected] > http://lists.qt-project.org/mailman/listinfo/pyside > >
_______________________________________________ PySide mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/pyside
