QDataWidgetMapper and custom widget - read value
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.
Q_PROPERTY declares date() as function to read property value; you must define it.
This means you need to declare and implement this function:
class YourClass: public QFrame
QDate date () const;
I have methods.
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:
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.
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?
I reported bug.