View Full Version : QDateEdit clear()

Henry Blue Heeler
25th September 2014, 03:36
QDateEdit clear() clears only the currentSection

dateEdit->clear(); // this clears the Day

dateEdit->clear(); // this does not clear the Month because the blank Day is invalid

Workarounds like the following clear the dateEdit field, but then a date like 09/24/2014 cannot be entered.
Only the calendar popup works to set the date in the dateEdit field.

dateEdit->setSpecialValueText( " " );
dateEdit->setDate( QDate::fromString( "01/01/0001", "dd/MM/yyyy" ) );

I've reviewed many suggestions, here and elsewhere and none work.

The next course of action is to derive QLineEdit, unless somebody else has a better idea.

QT 5.1.1 Win 7 x64

25th September 2014, 11:53
Maybe setText(QSting())?

Or deriving from QDateEdit and create a clear function that calls lineEdit()->clear()?


Henry Blue Heeler
25th September 2014, 22:41
setText() is not a member of QDateEdit.
I derived QDateEdit but lineEdit()->clear() does nothing.
Thanks for responding, anyway.

This is a recurring theme/issue with QDateEdit and QDateTimeEdit.

26th September 2014, 00:24
You should first ask yourself what you expect to obtain after calling clear -- I mean, what the date/time returned by the widget should be after clear is called. The widget represents time or date, one that exists, so calling clear() would have to enter a valid date into the widget. The best you can do is to define QAbstractSpinBox::specialValueText for your widget and instead of calling clear(), simply call setDate(minimum()) which will make your widget show the text you defined (can be empty). How you interpret that value is up to you.