PySide newbie question
-
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, QtCoreclass Communicate(QtCore.QObject) :
mySignal = QtCore.Signal() #signal madeother signals here
class AClass(QtGui.QWidget) :
def init(self) :
super(AClass, self).init()
self.initUI()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.setGeometry(300,300,290,150) self.setWindowTitle('Emit Signal') self.show() 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()
sys.exit(app.exec_())if name == 'main' :
main()@
-
@
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\Models.py", line 84, in setData
self.dataChanged[index, index].emit()
IndexError: Signature dataChanged() not found for signal: dataChangedWhat 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 worksP.S. i might still be a little wrong as i am not quite experienced in PySide and Python yet... still learning...