[PyKDE] QSqlEditorFactory.createEditor invocation problem, possibly PyQt bug

Phil Thompson phil at river-bank.demon.co.uk
Wed Jun 19 19:11:00 BST 2002

Hans-Peter Jansen wrote:

> Hi Phil et al.,
> after mangling my code for some hours, I'm suspect a PyQt problem
> in QSqlEditorFactory.
> This is the code in qt3/examples/sql/overview/table3/main.h:
> class CustomSqlEditorFactory : public QSqlEditorFactory
> {
>     Q_OBJECT
>     public:
> 	QWidget *createEditor( QWidget *parent, const QSqlField *field );
> };
> and in main.cpp:
> QWidget *CustomSqlEditorFactory::createEditor(
>     QWidget *parent, const QSqlField *field )
> {
>     if ( field->name() == "statusid" ) {
> 	QWidget *editor = new StatusPicker( parent );
> 	return editor;
>     }
>     return QSqlEditorFactory::createEditor( parent, field );
> }
> My corresponding python version:
> class CustomSqlEditorFactory(QSqlEditorFactory):
>     def __init__(self):
>         print "CustomSqlEditorFactory.__init__"
>         QSqlEditorFactory.__init__(self)
>     def createEditor(self, parent, field):
>         print "createEditor:", parent, field
>         if str(field.name()) == "statusid":
>             return StatusPicker(parent)
>         else:
>             return QSqlEditorFactory.createEditor(parent, field)
> The constuctor gets called, but createEditor doesn't. The PyQt docs
> state, this class is fully implemented, but Boudewijn gave me the
> hint, that it has two methods with the same name and the same number
> of arguments. Could it be the problem here?

createEditor() gets called if I right click and select "Insert". You

then hit other problems - the following fixes the immediate ones:

     def createEditor(self, parent, field):
         print "createEditor:", parent, field
             if str(field.name()) == "statusid":
                 return StatusPicker(parent)
         except AttributeError:

         return QSqlEditorFactory.createEditor(self, parent, field)

You have to be careful because the Python createEditor() re-implements

all C++ methods of the same name that are in scope. There are two in 
this case so the code needs to determine which it is supposed to do. In 
the above I assume it's the one I'm interested in, and handle the 
exception if it turns out not to be the right one.

You then hit the bugs in StatusPicker, but they seem to be fairly obvious.


More information about the PyQt mailing list