PySide newbie question

  • In QAbstractItemModel documentation is says that you have to emit a dataChanged signal after changes via SetData. How do i do that in python?

    Cheers, Lars

  • In PySide, all signals reside in a seperate class... Ex -

    This creates a blank window which closes upon mouse-click.

    import sys
    from PySide import QtGui, QtCore

    class Communicate(QtCore.QObject) :
    mySignal = QtCore.Signal() #signal made

    other signals here

    class AClass(QtGui.QWidget) :
    def init(self) :
    super(AClass, self).init()

    def initUI(self) :
        self.c = Communicate() #create instance of the signals' class
        self.c.mySignal.connect(self.close) #connect the 'mySignal' signal to QWidget's 'close' method

    Setting up the window

        self.setWindowTitle('Emit Signal')
    def mousePressEvent(self,event) :
        self.c.mySignal.emit() # reimplement 'mousePressEvent' to emit 'mySignal'

    Boilerplate required to run the application

    def main() :
    app = QtGui.QApplication(sys.argv)
    ex = AClass()

    if name == 'main' :


  • Thanks for the quick reply,

    i saw similar examples, but where does this dataChanged(index, index) predefined method (function?) fit in?

    Cheers, Lars

  • @
    class MyItemModel(QtCore.QAbstractItemModel) :

    other code here

    def setData(self, index, value[, role = Qt.EditRole]) :
    #   code for setting your data
        self.dataChanged.emit(topLeft, bottomRight) //... emit the data changed signal

    basically the signal is used as a notification when the data changes

    [EDIT] - syntax for signal emitting corrected

  • I must be missing something; i tried you example as follows:

    def setData(self, index, value, role):
    if index.isValid() and index.column() == 0 and role == QtCore.Qt.EditRole:
    index.internalPointer().name = value
    self.dataChanged[index, index].emit() #only the one cell changes

    But i am still getting an error:

    Traceback (most recent call last):
    File "D:\Documents\Code\Eclipse\workspace\FlowWare_1\design\", line 84, in setData
    self.dataChanged[index, index].emit()
    IndexError: Signature dataChanged() not found for signal: dataChanged

    What am i missing?

    Cheers, Lars

  • Hey, my bad there...
    @self.dataChanged[index, index].emit()@
    is wrong... this syntax is for connecting it with a slot( dataChanged[index, index].connect(...) )

    change it to
    @self.dataChanged.emit(index, index)@
    and see if it works

    P.S. i might still be a little wrong as i am not quite experienced in PySide and Python yet... still learning...

  • Yes, that was it, thanks a lot.

    I am still confused, and start on the tutorial again.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.