[PyQt] Connecting to a QItemModel
Mads Ipsen
mpi at comxnet.dk
Sat Mar 7 09:47:09 GMT 2009
> On Fri, Mar 6, 2009 at 6:22 PM, Mads Ipsen <mpi at comxnet.dk> wrote:
>>> How does one connect to the signals of a QItemModel?
>>>
>>> I tried the following, but it didn't work:
>>>
>>> self.connect(
>>> self.model,
>>> QtCore.SIGNAL('itemChanged(QStandardItem 8)'),
>>> self.on_model_itemChanged
>>> )
>>>
>>> and
>>>
>>> self.connect(
>>> self.model,
>>> QtCore.SIGNAL('itemChanged(QStandardItem &)'),
>>> self.on_model_itemChanged
>>> )
>>>
>>> Neither worked.
>>>
>
>>
>>
>> I believe you should do:
>>
>> self.connect(self.model,
>> QtCore.SIGNAL('itemChanged( QStandardItem *)'),
>> self.foo)
>>
>> At least that works for me.
>>
>> Best, Mads
>>
>
> I tried that. That '8' was supposed to have been an '*'
>
>
> --
> Fedora 9 : sulphur is good for the skin
> ( www.pembo13.com )
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
This small example uses the connection setup from my previous post. It
emits the signal 10 times. The signal it connected to foo(), which prints
out the changed item. Just save it and run to see for your self.
import sys
from PyQt4 import QtCore, QtGui
def foo(item):
print item
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
# Setup a model
model = QtGui.QStandardItemModel()
# Connect it
model.connect(model, QtCore.SIGNAL('itemChanged( QStandardItem *)'), foo)
# Add 10 dummy elements
for i in range(10):
item = QtGui.QStandardItem(str(i))
model.appendRow([item])
# Set them to be checked - this will trigger the 'itemChanged' signal
for row in range(model.rowCount()):
item = model.item(row, 0)
item.setCheckState(QtCore.Qt.Checked)
More information about the PyQt
mailing list