PDA

View Full Version : QDataWidgetMapper and custom widget - read value



Hostel
10th May 2013, 22:02
I’ve made a my widget which has a Q_PROPERTY like this:


Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged USER true )

I created a QDataWidgetMapper and addMapping. The date from my widget is not readed by mapper. Even there is not invoked a date() method. What could be wrong? My class inherits from QFrame and has a Q_OBJECT macro.

wysota
11th May 2013, 09:05
Your code looks ok. You can try using a custom delegate with reimplemented setModelData() and setEditorData().

Santosh Reddy
11th May 2013, 09:58
I created a QDataWidgetMapper and addMapping. The date from my widget is not readed by mapper. Even there is not invoked a date() method. What could be wrong? My class inherits from QFrame and has a Q_OBJECT macro.
What model is the mapper using? I guess the mapped section of the model does not return the QDate (in the QVariant).

Hostel
11th May 2013, 12:07
I use QSqlTableModel.
My widget has QCheckBox and QDateEdit. I use delegate to format date for SQLite.

I made tests and I added my delegate. I have two situations:

1. Without mapper->setSubmitPolicy (default is QDataWidgetMapper::AutoSubmit).
setModelData from delegate is invoked for Qt widgets(QDateEdit too) but not when I set value in my widget.

2. With mapper->setSubmitPolicy( QDataWidgetMapper::ManualSubmit ).
submit() is called whed dialog is accepted. In this case setModelData operates on Qt widgets and take value from my widget too.

Is this a bug or maybe I'm doing something wrong?