[PySide] can a QStandardItem emit a signal?

Frank Rueter | OHUfx frank at ohufx.com
Thu Aug 4 06:31:37 CEST 2016


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



-- 
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>* *

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160804/e243798d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ohufxLogo_50x50.png
Type: image/png
Size: 2666 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160804/e243798d/attachment.png>


More information about the PySide mailing list