Qt-interest Archive, June 2007
QDateTimeEdit & NULL value?
Message 1 in thread
Hi!
This question has been asked here several times, but I couldn't find a
working solution for Qt4, so it's time to ask again since things might have
changed ;-)
So my questions are:
*) Can I somehow make QDateTimeEdit (and QDateEdit/QTimeEdit) accept and
display NULL values (i.e., an empty date/time)?
*) Can I achieve this behaviour by subclassing an "original" Qt class and
reimplementing some of its methods?
As far as I understand from the source code, the non-null constraint is firmly
hardcoded in private and/or non-virtual methods, so I do not see an easy
solution to this problem (I do not consider cloning the entire QDateTimeEdit
code and adding the required behaviour an "easy solution"). On the other
hand, allowing empty date fields is such an obvious requirement (which has
been pointed out several times) that I can hardly believe it is not supported,
so are we missing something obvious?
Thanks & kind regards,
Markus
P.S.: Here are some of the previous instances of this issue:
http://lists.trolltech.com/qt-interest/2002-01/thread01392-0.html
http://lists.trolltech.com/qt-interest/2003-04/thread01631-0.html
http://lists.trolltech.com/qt-interest/2006-06/thread00542-0.html
--
[ signature omitted ]
Message 2 in thread
On Mon, 2007-06-18 at 22:25 +0200, Markus Grabner wrote:
> Hi!
>
> This question has been asked here several times, but I couldn't find a
> working solution for Qt4, so it's time to ask again since things might have
> changed ;-)
>
> So my questions are:
> *) Can I somehow make QDateTimeEdit (and QDateEdit/QTimeEdit) accept and
> display NULL values (i.e., an empty date/time)?
> *) Can I achieve this behaviour by subclassing an "original" Qt class and
> reimplementing some of its methods?
>
You cannot make QDateTimeEdit accept NULL values. To do a proper job you
would have to modify (or clone) QDateTimeEdit, but I can confirm that
provided you accept some compromises, you can achieve this essential
feature by subclassing. I have recently done this (date only) for a
client (closed source I'm afraid) and it took me a day, using pointers
provided by Trolltech support.
There are a number of trackers on the issue, the first of which shows
Scheduled For "5.0.0 (Next Major Release)".
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=135683
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=141703
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=140476
> As far as I understand from the source code, the non-null constraint is firmly
> hardcoded in private and/or non-virtual methods, so I do not see an easy
> solution to this problem (I do not consider cloning the entire QDateTimeEdit
> code and adding the required behaviour an "easy solution"). On the other
> hand, allowing empty date fields is such an obvious requirement (which has
> been pointed out several times) that I can hardly believe it is not supported,
> so are we missing something obvious?
>
I can hardly believe it either, but that is indeed the case, and as you
have observed the constraint is firmly embedded in the class.
Hope this helps,
Stephen Jackson
--
[ signature omitted ]