[PyQt] QDataWidgetMapper and addMapping with a custom property name: setProperty never called
Phil Thompson
phil at riverbankcomputing.com
Tue Nov 9 22:30:18 GMT 2010
On Tue, 9 Nov 2010 20:29:43 +0100, TP <paratribulations at free.fr> wrote:
> Hello,
>
> I currently use QDataWidgetMapper with a custom property name:
>
> self.mapper.addMapping( widget, index, propertyName )
>
> Now let us look at the private method populate() of
> src/gui/itemviews/qdatawidgetmapper.cpp (Qt source code):
>
> //////
> void QDataWidgetMapperPrivate::populate(WidgetMapper &m)
> {
> if (m.widget.isNull())
> return;
>
> m.currentIndex = indexAt(m.section);
> if (m.property.isEmpty())
> delegate->setEditorData(m.widget, m.currentIndex);
> else
> m.widget->setProperty(m.property,
> m.currentIndex.data(Qt::EditRole));
> }
> //////
>
> So, the .setEditorData() method of the delegate is called when there is
no
> custom property name, and on the contrary the .setProperty() method of
the
> widget under consideration is called when a custom property name is
> specified (this is my case).
>
> I use QTextEdit with a custom property name ("plainText" instead of the
> default property "html"), I have tried to write my own QTextEdit,
> QTextEdit2, with a specialized setProperty method to perform some action
> before setting the property:
>
> class QTextEdit2( QTextEdit ):
> def __init__( self, parent = None ):
> super( QTextEdit2, self ).__init__( parent )
> def setProperty( self, name, qvariant ):
> # some code to do some action
> super( QTextEdit2, self ).setProperty( name, qvariant )
>
> But this *setProperty method is never called*, contrary of what we
should
> expect due to the code of QDataWidgetMapper.cpp above!
> All is happening as if the setProperty method of the C++ parent object
> (QTextEdit) is called, but not the method setProperty defined in the
> Python
> code of the used widget, QTextEdit2.
>
> What is the problem?
setProperty() isn't virtual so you can't reimplement it in Python.
Phil
More information about the PyQt
mailing list