Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QDateTimeEdit Class Reference

The QDateTimeEdit class provides a widget for editing dates and times. More...

    #include <QDateTimeEdit>

Inherits QAbstractSpinBox.

- List of all members, including inherited members

### Public Types

- enum Section { NoSection, AMPMSection, MSecsSection, SecondsSection, MinutesSection, ..., YearsSection }
- typedef Sections

### Writable Properties

- currentSection : Section
- date : QDate
- dateTime : QDateTime
- format : QString
- maximumDate : QDate

- maximumTime : QTime
- minimumDate : QDate
- minimumTime : QTime
- time : QTime

- 6 writable properties inherited from QAbstractSpinBox
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- display : Sections

- 2 read-only properties inherited from QAbstractSpinBox
- 24 read-only properties inherited from QWidget

### Public Functions

- QDateTimeEdit ( QWidget * parent = 0 )
- QDateTimeEdit ( const QDateTime & datetime, QWidget * parent = 0 )
- QDateTimeEdit ( const QDate & date, QWidget * parent = 0 )
- QDateTimeEdit ( const QTime & time, QWidget * parent = 0 )
- QString sectionText ( Section section ) const
- void setDateRange ( const QDate & min, const QDate & max )
- void setTimeRange ( const QTime & min, const QTime & max )

- 2 public functions inherited from QAbstractSpinBox
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- void setDate ( const QDate & date )
- void setDateTime ( const QDateTime & dateTime )
- void setTime ( const QTime & time )

- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void dateChanged ( const QDate & date )
- void dateTimeChanged ( const QDateTime & datetime )
- void timeChanged ( const QTime & time )

- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- virtual QString mapDateTimeToText ( const QDateTime & date ) const
- virtual QDateTime mapTextToDateTime ( QString * txt, QValidator::State * state ) const

- 3 protected functions inherited from QAbstractSpinBox
- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

## Detailed Description

The QDateTimeEdit class provides a widget for editing dates and times.

QDateTimeEdit allows the user to edit dates by using the keyboard or the arrow keys to increase and decrease date and time values. The arrow keys can be used to move from section to section within the QDateTimeEdit box. Dates and times appear in accordance with the format set; see setFormat().

        QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate());
        dateEdit->setMinimumDate(QDate::currentDate().addDays(-365));
        dateEdit->setMaximumDate(QDate::currentDate().addDays(365));
        dateEdit->setFormat("yyyy.MM.dd");

Here we've created a new QDateTimeEdit object initialized with today's date, and restricted the valid date range to today plus or minus 365 days. We've set the order to month, day, year. If the auto advance property is true (as we've set it here) when the user completes a section of the date, e.g. enters two digits for the month, they are automatically taken to the next section.

The maximum and minimum values for a date value in the date editor default to the maximum and minimum values for a QDate. You can change this by calling setMinimumDate(), setMaximumDate(), setMinimumTime(), and setMaximumTime().

## Member Type Documentation

### enum QDateTimeEdit::Section
typedef QDateTimeEdit::Sections

`QDateTimeEdit::NoSection` |
`QDateTimeEdit::AMPMSection` |
`QDateTimeEdit::MSecsSection` |
`QDateTimeEdit::SecondsSection` |
`QDateTimeEdit::MinutesSection` |
`QDateTimeEdit::HoursSection` |
`QDateTimeEdit::DaysSection` |
`QDateTimeEdit::MonthsSection` |
`QDateTimeEdit::YearsSection` |

The Sections typedef can store a combination of Section values.

## Property Documentation

### currentSection : Section

This property holds the current section of the spinbox setCurrentSection().

Access functions:

- Section currentSection () const
- void setCurrentSection ( Section section )

### date : QDate

This property holds the that is set in the .

Access functions:

- QDate date () const
- void setDate ( const QDate & date )

See also setDate().

### dateTime : QDateTime

This property holds the that is set in the .

Access functions:

- QDateTime dateTime () const
- void setDateTime ( const QDateTime & dateTime )

See also setDateTime().

### display : Sections

This property holds the currently displayed fields of the date time edit.

Returns a bit set of the displayed sections for this format. setFormat(), format()

Access functions:

- Sections display () const

### format : QString

This property holds the format used to display the time/date of the date time edit.

This format is a subset of the format described in QDateTime::toString()

These expressions may be used:

Expression | Output
--- | ---
hh | the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
mm | the minute with a leading zero (00 to 59)
ss | the second whith a leading zero (00 to 59)
zzz | the milliseconds with leading zeroes (000 to 999)
AP | use AM/PM display. AP will be replaced by either "AM" or "PM".
ap | use am/pm display. ap will be replaced by either "am" or "pm".
dd | the day as number with a leading zero (01 to 31)
MM | the month as number with a leading zero (01 to 12)
MMM | the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName().
yy | the year as two digit number (00 to 99)
yyyy | the year as four digit number (1752 to 8000)

All other input characters or sequence of characters that are enclosed in singlequotes will be treated as text and can be used as delimiters.

Example format strings (assuming that the QDate is the 20<sup><small>th</small></sup> July 1969):

Format | Result
--- | ---
dd.MM.yyyy | 20.07.1969
MMM d yy | Jul 20 69

If you specify an invalid format the format will not be set.

Multiple instances of the same field is not allowed. E.g.

setFormat("yyyy.MM.yy"); // not allowed

a format with no valid fields is not allowed either. E.g.

setFormat("s.M.y"); // not allowed

Warning: Since QDateTimeEdit internally always operates on a QDateTime changing the format can change the minimum[Time|Date]s and the current[Time|Date]. E.g.

        QDateTimeEdit edit(0); // format is "yyyy.MM.dd hh:mm:ss"
        edit.setMinimumDate(QDate(2000, 1, 1));
        edit.setMaximumDate(QDate(2003, 1, 1));
        edit.setDateTime(QDateTime(QDate(2002, 5, 5), QTime(10, 10, 10)));
        edit.setFormat("hh:mm:ss");

        // edit can no longer display dates. This means that the
        // minimum and maximum date will be set to the current date,
        // e.g. 2002, 5, 5.

Access functions:

- QString format () const
- bool setFormat ( const QString & format )

See also QDateTime::toString(), setFormat(), and display().

### maximumDate : QDate

This property holds the maximum date of the date time edit.

When setting this property the QDateTimeEdit::minimumDate is adjusted if necessary to ensure that the range remains valid. If the date is not a valid QDate object, this function does nothing.

The default minimum value can be restored with clearMinimumDate().

Access functions:

- QDate maximumDate () const
- void setMaximumDate ( const QDate & max )
- void clearMaximumDate ()

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), setTimeRange(), setDateRange(), and QDate::isValid().

### maximumTime : QTime

This property holds the maximum time of the date time edit.

When setting this property the QDateTimeEdit::maximumTime is adjusted if necessary to ensure that the range remains valid. If the time is not a valid QTime object, this function does nothing.

The default minimum value can be restored with clearMinimumDate().

Access functions:

- QTime maximumTime () const
- void setMaximumTime ( const QTime & max )
- void clearMaximumTime ()

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), setTimeRange(), setDateRange(), and QTime::isValid().

### minimumDate : QDate

This property holds the minimum date of the date time edit.

When setting this property the QDateTimeEdit::maximumDate is adjusted if necessary, to ensure that the range remains valid. If the date is not a valid QDate object, this function does nothing.

The default minimum value can be restored with clearMinimum().

Access functions:

- QDate minimumDate () const
- void setMinimumDate ( const QDate & min )
- void clearMinimumDate ()

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimum(), setTimeRange(), setDateRange(), and QDate::isValid().

### minimumTime : QTime

This property holds the minimum time of the date time edit.

When setting this property the QDateTimeEdit::maximumTime is adjusted if necessary, to ensure that the range remains valid. If the time is not a valid QTime object, this function does nothing.

The default minimum value can be restored with clearMinimumTime().

Access functions:

- QTime minimumTime () const
- void setMinimumTime ( const QTime & min )
- void clearMinimumTime ()

See also setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setTimeRange(), setDateRange(), and QTime::isValid().

### time : QTime

This property holds the that is set in the .

Access functions:

- QTime time () const
- void setTime ( const QTime & time )

See also setTime().

## Member Function Documentation

### QDateTimeEdit::QDateTimeEdit ( QWidget * parent = 0 )

Constructs an empty date time editor with a parent. The format is set to "yyyy.MM.dd hh:mm:ss" by default.

### QDateTimeEdit::QDateTimeEdit ( const QDateTime & datetime, QWidget * parent = 0 )

Constructs an empty date time editor with a parent. The value is set to datetime. The format is set to "yyyy.MM.dd hh:mm:ss" by default.

### QDateTimeEdit::QDateTimeEdit ( const QDate & date, QWidget * parent = 0 )

Constructs an empty date time editor with a parent. The value is set to date. The format is set to "yyyy.MM.dd".

### QDateTimeEdit::QDateTimeEdit ( const QTime & time, QWidget * parent = 0 )

Constructs an empty date time editor with a parent. The value is set to time. The format is set to "hh:mm:ss".

### void QDateTimeEdit::dateChanged ( const QDate & date ) `[signal]`

This signal is emitted whenever the date is changed. The new date is passed in date.

### void QDateTimeEdit::dateTimeChanged ( const QDateTime & datetime ) `[signal]`

This signal is emitted whenever the date or time is changed. The new date and time is passed in datetime.

### QString QDateTimeEdit::mapDateTimeToText ( const QDateTime & date ) const `[virtual protected]`

This virtual function is used by the date time edit whenever it needs to display the date.

If you reimplement this, you may also need to reimplement mapTextToValue().

See also mapTextToValue().

### QDateTime QDateTimeEdit::mapTextToDateTime ( QString * txt, QValidator::State * state ) const `[virtual protected]`

This virtual function is used by the date time edit whenever it needs to interpret text entered by the user as a value. The user's text is passed in txt and the validator's state in state.

See also mapDateTimeToText().

### QString QDateTimeEdit::sectionText ( Section section ) const

Returns the text from the given section.

See also cleanText() and currentSection().

### void QDateTimeEdit::setDateRange ( const QDate & min, const QDate & max )

Convenience function to set minimum and maximum date with one function call.

        setDateRange(min, max);

is analogous to:

        setMinimumDate(min);
        setMaximumDate(max);

If either min or max are not valid, this function does nothing.

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QDate::isValid().

### void QDateTimeEdit::setTimeRange ( const QTime & min, const QTime & max )

Convenience function to set minimum and maximum time with one function call.

        setTimeRange(min, max);

is analogous to:

        setMinimumTime(min);
        setMaximumTime(max);

If either min or max are not valid, this function does nothing.

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QTime::isValid().

### void QDateTimeEdit::timeChanged ( const QTime & time ) `[signal]`

This signal is emitted whenever the time is changed. The new time is passed in time.