Results 1 to 4 of 4

Thread: QDateEdit clear()

  1. #1
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default QDateEdit clear()

    QDateEdit clear() clears only the currentSection
    Qt Code:
    1. dateEdit->setSelectedSection(QDateEdit::DaySection);
    2. dateEdit->clear(); // this clears the Day
    3.  
    4. dateEdit->setSelectedSection(QDateEdit::MonthSection);
    5. dateEdit->clear(); // this does not clear the Month because the blank Day is invalid
    To copy to clipboard, switch view to plain text mode 
    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.
    Qt Code:
    1. dateEdit->setSpecialValueText( " " );
    2. dateEdit->setDate( QDate::fromString( "01/01/0001", "dd/MM/yyyy" ) );
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDateEdit clear()

    Maybe setText(QSting())?

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

    Cheers,
    _

  3. #3
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QDateEdit clear()

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDateEdit clear()

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to put empty value in QDateEdit?
    By sawerset in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2019, 21:06
  2. QDateEdit in QTableWidget
    By ceddy in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2012, 16:13
  3. clear text in QDateEdit
    By dyams in forum Qt Programming
    Replies: 6
    Last Post: 31st August 2010, 22:30
  4. Null for QDateEdit
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2009, 21:54
  5. Subclassing QDateEdit
    By jamadagni in forum Qt Programming
    Replies: 6
    Last Post: 4th February 2006, 13:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.