PDA

View Full Version : QDateEdit clear()



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


dateEdit->setSelectedSection(QDateEdit::DaySection);
dateEdit->clear(); // this clears the Day

dateEdit->setSelectedSection(QDateEdit::MonthSection);
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

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

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

Cheers,
_

Henry Blue Heeler
25th September 2014, 21: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.

wysota
25th September 2014, 23: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.