[PyKDE] Validating user input - PyQt
David Boddie
david at boddie.org.uk
Tue Sep 5 21:13:28 BST 2006
On Tuesday 05 September 2006 12:35:23 +0100, joanne matthews wrote:
> I would like to validate user input in a table. The input needs to be a
> double between 0 and 1 with 4 decimal places. I've implemented some code
> to do the job and it Works fine if I create the table and set the
> delegate from within the main method. However, when The table is defined
> within a method in a class, the system crashes with the message
> "python.exe has encountered a problem...". I'd really appreciate it if
> someone could take a look. Here's my code below:
[...]
> def createTable(self,col,row=None):
> table = QtGui.QTableWidget(row, col)
> table.setShowGrid(True)
> palette = QtGui.QPalette()
>
> palette.setColor(QtGui.QPalette.Active,
> QtGui.QPalette.ColorRole(16),
> QtGui.QColor(204,0,0))
> table.setAlternatingRowColors(1)
>
> table.setSelectionBehavior(
> QtGui.QAbstractItemView.SelectionBehavior(1))
> table.setSelectionMode(QtGui.QAbstractItemView.SelectionMode(1))
>
> table.horizontalHeader().setResizeMode(
> QtGui.QHeaderView.Stretch)
>
> delegate = lineEditDelegate()
> table.setItemDelegate(delegate)
>
> return table
If I remember correctly, the view doesn't take ownership of the delegate, so
when it goes out of scope it gets garbage collected. You need to either
keep a reference to it in the class or create it with
delegate = lineEditDelegate(self)
so that the view can delete it when it's finished with it.
David
More information about the PyQt
mailing list