View Full Version : Using QDataWidgetMapper with custom types

19th August 2011, 14:43
Good day.

I have the following problem:
1.) I have created a custom datatype "myType", declared it and it works like a charm.
It includes an integer and a QStringList.

2.) I am using this type in my model - it is a QAbstractItemModel based tree model. When i am creating the model structure i create this type, insert it into a QVariant and attach the QVariant into a Node. No surprises here.

3.) The model returns the QVariant including my type in the data() function. Also standard procedure.

4.) In my view i am using QDataWidgetMapper to map widgets to the model.
When i map my widgets there are no problems with the standard datatypes. But when i map my custom type to a widget, the widget does not get updated.

I understand that i could return only the integer part of my type in my model's data() function, but i need access to the QStringList from my View.

Is it possible to integrate a custom type into QVariant so the QDataWidgetMapper will automatically map the desired type variable to my widget? If yes, how?

p.s. I have not included any source code because it would in my opinion clutter the question, and because my final question is quite simple. Thank you.

19th August 2011, 15:55
It's likely you should set a custom delegate on the data widget mapper if you are using custom types and implement setModelData()/setEditorData().

25th August 2011, 10:42
Thank you, that was exactly what I needed to do.