[PyQt] Null dates in QDateEdit

Hans-Peter Jansen hpj at urpla.net
Thu Jan 10 11:52:36 GMT 2008


Am Donnerstag, 10. Januar 2008 schrieb Catriona Johnson:
> Hello
> I am new to PyQT and would appreciate help with the following problem.
> I have a database table that has, amongst other fields, a nullable
> date - EndDate. On my form I have a QDateEdit widget which I only want
> to show a value if the date is not null, a user will enter a date once
> there is one and this will often be on subsequent edits of the record.
> So my question is how are null dates handled with a QDateWidget?

This issue is one of the few weak areas of Qt3. I've no idea, how Qt4 behave 
in this particular case, but in PyQt3 I went off implementing my own QDate, 
QDateEdits and the time related classes for this (and some other) reasons.

In particular, dates stored as NULL in the database show as empty edits in 
sql forms - which is fine, but as soon as the user tabs over such a field, 
Qt insists in transfoming it into a valid date, which happens to result in 
2000-01-01.

Further hacks revealed, that it was not feasible to cast this behaviour out 
of QDateEdit without loosing important functionality (I tried really hard).

This is a real pity, since QDate has a concept of invalid dates, 
unfortunately QDateEdit doesn't. 

Hopefully, Qt4 improved in this area.

Cheers,
Pete


More information about the PyQt mailing list