[PyKDE] tableview and model
Olivier Fournier
o.fournier at perigord.com
Sat Feb 25 10:26:13 GMT 2006
thank's for your help
...
self.model = QtGui.QStandardItemModel(3,3)
self.TVTable.setModel(self.model)
...
is more correct...
olivier fournier
Phil Thompson a écrit :
>On Friday 24 February 2006 3:48 pm, Olivier Fournier wrote:
>
>
>>Hello,
>>
>>I don't understand why this code is correct :
>>
>># -*- coding: utf-8 -*-
>>
>># Form implementation generated from reading ui file 'ftable.ui'
>>#
>># Created: Fri Feb 24 16:38:19 2006
>># by: PyQt4 UI code generator vsnapshot-20060221
>>#
>># WARNING! All changes made in this file will be lost!
>>
>>import sys
>>from PyQt4 import QtCore, QtGui
>>
>>class Ui_FTable(object):
>> def setupUi(self, FTable):
>> FTable.setObjectName("FTable")
>>
>>FTable.resize(QtCore.QSize(QtCore.QRect(0,0,400,300).size()).expandedTo(FTa
>>ble.minimumSizeHint()))
>>
>> self.gridlayout = QtGui.QGridLayout(FTable)
>> self.gridlayout.setMargin(9)
>> self.gridlayout.setSpacing(6)
>> self.gridlayout.setObjectName("gridlayout")
>>
>> self.TVTable = QtGui.QTableView(FTable)
>> self.TVTable.setObjectName("TVTable")
>> self.gridlayout.addWidget(self.TVTable,0,0,1,1)
>>
>> self.retranslateUi(FTable)
>> QtCore.QMetaObject.connectSlotsByName(FTable)
>>
>> def tr(self, string):
>> return QtGui.QApplication.translate("FTable", string, None,
>>QtGui.QApplication.UnicodeUTF8)
>>
>> def retranslateUi(self, FTable):
>> FTable.setWindowTitle(self.tr("Form"))
>>
>>if __name__ == "__main__":
>> app = QtGui.QApplication(sys.argv)
>> FTable = QtGui.QWidget()
>> ui = Ui_FTable()
>> ui.setupUi(FTable)
>> ############################
>> model = QtGui.QStandardItemModel(3,3)
>> ui.TVTable.setModel(model)
>> ############################
>> FTable.show()
>> sys.exit(app.exec_())
>>
>>
>>and why this code is incorrect: ( Exit with Signal 11 )
>>
>># -*- coding: utf-8 -*-
>>
>>import sys
>>from PyQt4 import QtGui, QtCore
>>from ftable import Ui_FTable
>>
>>class FTable(Ui_FTable):
>> def __init__(self, Fenetre):
>> self.setupUi(Fenetre)
>>
>> model = QtGui.QStandardItemModel(3,3)
>> self.TVTable.setModel(model)
>>
>>
>>if __name__ == "__main__":
>> app = QtGui.QApplication(sys.argv)
>> Client = QtGui.QWidget()
>> ui = FTable(Fenetre=Client)
>> Client.show()
>> sys.exit(app.exec_())
>>
>>I use Python2.4 and the last sip and pyqt snapshot ( 20060221)
>>
>>I'll be happy you can help me!
>>
>>
>
>Because setModel() doesn't take ownership of the model. In the first example
>model stays alive while it is being used. In the second it is garbage
>collected while it is still in use.
>
>Phil
>
>_______________________________________________
>PyKDE mailing list PyKDE at mats.imk.fraunhofer.de
>http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
>
>
>
>
More information about the PyQt
mailing list