|  | Home · All Classes · Modules

# QDateTimeEdit Class Reference
[QtGui module]

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

Inherits QAbstractSpinBox.

Inherited by QDateEdit and QTimeEdit.

### Types

- enum Section { NoSection, AmPmSection, MSecSection, SecondSection, ..., DateSections_Mask }
- class Sections

### Methods

- __init__ (self, QWidget parent = None)
- __init__ (self, QDateTime, QWidget parent = None)
- __init__ (self, QDate, QWidget parent = None)
- __init__ (self, QTime, QWidget parent = None)
- bool calendarPopup (self)
- QCalendarWidget calendarWidget (self)
- clear (self)
- clearMaximumDate (self)
- clearMaximumDateTime (self)
- clearMaximumTime (self)
- clearMinimumDate (self)
- clearMinimumDateTime (self)
- clearMinimumTime (self)
- Section currentSection (self)
- int currentSectionIndex (self)
- QDate date (self)
- QDateTime dateTime (self)
- QDateTime dateTimeFromText (self, QString)
- Sections displayedSections (self)
- QString displayFormat (self)
- bool event (self, QEvent)
- QString input fixup (self, QString input)
- fixup (self, QString)
- focusInEvent (self, QFocusEvent)
- bool focusNextPrevChild (self, bool)
- initStyleOption (self, QStyleOptionSpinBox)
- keyPressEvent (self, QKeyEvent)
- QDate maximumDate (self)
- QDateTime maximumDateTime (self)
- QTime maximumTime (self)
- QDate minimumDate (self)
- QDateTime minimumDateTime (self)
- QTime minimumTime (self)
- mousePressEvent (self, QMouseEvent)
- paintEvent (self, QPaintEvent)
- Section sectionAt (self, int)
- int sectionCount (self)
- QString sectionText (self, Section)
- setCalendarPopup (self, bool)
- setCalendarWidget (self, QCalendarWidget)
- setCurrentSection (self, Section)
- setCurrentSectionIndex (self, int)
- setDate (self, QDate)
- setDateRange (self, QDate, QDate)
- setDateTime (self, QDateTime)
- setDateTimeRange (self, QDateTime, QDateTime)
- setDisplayFormat (self, QString)
- setMaximumDate (self, QDate)
- setMaximumDateTime (self, QDateTime)
- setMaximumTime (self, QTime)
- setMinimumDate (self, QDate)
- setMinimumDateTime (self, QDateTime)
- setMinimumTime (self, QTime)
- setSelectedSection (self, Section)
- setTime (self, QTime)
- setTimeRange (self, QTime, QTime)
- setTimeSpec (self, Qt.TimeSpec)
- QSize sizeHint (self)
- stepBy (self, int)
- QAbstractSpinBox.StepEnabled stepEnabled (self)
- QString textFromDateTime (self, QDateTime)
- QTime time (self)
- Qt.TimeSpec timeSpec (self)
- (QValidator.State, QString input, int pos) validate (self, QString input, int pos)
- (QValidator.State, int) validate (self, QString, int)
- wheelEvent (self, QWheelEvent)

### Qt Signals

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

## 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 setDisplayFormat().

     QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate.currentDate());
     dateEdit->setMinimumDate(QDate.currentDate().addDays(-365));
     dateEdit->setMaximumDate(QDate.currentDate().addDays(365));
     dateEdit->setDisplayFormat("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.

The minimum value for QDateTimeEdit is 14 September 1752, and 2 January 4713BC for QDate. You can change this by calling setMinimumDate(), setMaximumDate(), setMinimumTime(), and setMaximumTime().

### Using a Pop-up Calendar Widget

QDateTimeEdit can be configured to allow a QCalendarWidget to be used to select dates. This is enabled by setting the calendarPopup property. Additionally, you can supply a custom calendar widget for use as the calendar pop-up by calling the setCalendarWidget() function. The existing calendar widget can be retrieved with calendarWidget().

| A date time editing widget shown in the Windows XP widget style.
| A date time editing widget shown in the Macintosh widget style.
| A date time editing widget shown in the Plastique widget style.

## Type Documentation

### QDateTimeEdit.Section

Constant | Value
--- | ---
`QDateTimeEdit.NoSection` | `0x0000`
`QDateTimeEdit.AmPmSection` | `0x0001`
`QDateTimeEdit.MSecSection` | `0x0002`
`QDateTimeEdit.SecondSection` | `0x0004`
`QDateTimeEdit.MinuteSection` | `0x0008`
`QDateTimeEdit.HourSection` | `0x0010`
`QDateTimeEdit.DaySection` | `0x0100`
`QDateTimeEdit.MonthSection` | `0x0200`
`QDateTimeEdit.YearSection` | `0x0400`

The Sections type is a typedef for QFlags<Section>. It stores an OR combination of Section values.

## Method Documentation

### QDateTimeEdit.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs an empty date time editor with a parent.

### QDateTimeEdit.__init__ (self, QDateTime, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs an empty date time editor with a parent. The value is set to datetime.

### QDateTimeEdit.__init__ (self, QDate, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs an empty date time editor with a parent. The value is set to date.

### QDateTimeEdit.__init__ (self, QTime, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs an empty date time editor with a parent. The value is set to time.

### bool QDateTimeEdit.calendarPopup (self)

### QCalendarWidget QDateTimeEdit.calendarWidget (self)

Returns the calendar widget for the editor if calendarPopup is set to true and (sections() & DateSections_Mask) != 0.

This function creates and returns a calendar widget if none has been set.

This function was introduced in Qt 4.4.

See also setCalendarWidget().

### QDateTimeEdit.clear (self)

Reimplemented from QAbstractSpinBox.clear().

### QDateTimeEdit.clearMaximumDate (self)

### QDateTimeEdit.clearMaximumDateTime (self)

### QDateTimeEdit.clearMaximumTime (self)

### QDateTimeEdit.clearMinimumDate (self)

### QDateTimeEdit.clearMinimumDateTime (self)

### QDateTimeEdit.clearMinimumTime (self)

### Section QDateTimeEdit.currentSection (self)

### int QDateTimeEdit.currentSectionIndex (self)

### QDate QDateTimeEdit.date (self)

### QDateTime QDateTimeEdit.dateTime (self)

### QDateTime QDateTimeEdit.dateTimeFromText (self, QString)

Returns an appropriate datetime for the given text.

This virtual function is used by the datetime edit whenever it needs to interpret text entered by the user as a value.

See also textFromDateTime() and validate().

### Sections QDateTimeEdit.displayedSections (self)

### QString QDateTimeEdit.displayFormat (self)

### bool QDateTimeEdit.event (self, QEvent)

Reimplemented from QObject.event().

### QString input QDateTimeEdit.fixup (self, QString input)

Reimplemented from QAbstractSpinBox.fixup().

### QDateTimeEdit.fixup (self, QString)

### QDateTimeEdit.focusInEvent (self, QFocusEvent)

Reimplemented from QWidget.focusInEvent().

### bool QDateTimeEdit.focusNextPrevChild (self, bool)

Reimplemented from QWidget.focusNextPrevChild().

### QDateTimeEdit.initStyleOption (self, QStyleOptionSpinBox)

Initialize option with the values from this QDataTimeEdit. This method is useful for subclasses when they need a QStyleOptionSpinBox, but don't want to fill in all the information themselves.

See also QStyleOption.initFrom().

### QDateTimeEdit.keyPressEvent (self, QKeyEvent)

Reimplemented from QWidget.keyPressEvent().

### QDate QDateTimeEdit.maximumDate (self)

### QDateTime QDateTimeEdit.maximumDateTime (self)

### QTime QDateTimeEdit.maximumTime (self)

### QDate QDateTimeEdit.minimumDate (self)

### QDateTime QDateTimeEdit.minimumDateTime (self)

### QTime QDateTimeEdit.minimumTime (self)

### QDateTimeEdit.mousePressEvent (self, QMouseEvent)

Reimplemented from QWidget.mousePressEvent().

### QDateTimeEdit.paintEvent (self, QPaintEvent)

Reimplemented from QWidget.paintEvent().

### Section QDateTimeEdit.sectionAt (self, int)

Returns the Section at index.

If the format is 'yyyy/MM/dd', sectionAt(0) returns YearSection, sectionAt(1) returns MonthSection, and sectionAt(2) returns YearSection,

This function was introduced in Qt 4.3.

### int QDateTimeEdit.sectionCount (self)

### QString QDateTimeEdit.sectionText (self, Section)

Returns the text from the given section.

See also currentSection().

### QDateTimeEdit.setCalendarPopup (self, bool)

### QDateTimeEdit.setCalendarWidget (self, QCalendarWidget)

The QCalendarWidget argument has it's ownership transferred to Qt.

Sets the given calendarWidget as the widget to be used for the calendar pop-up. The editor does not automatically take ownership of the calendar widget.

This function was introduced in Qt 4.4.

See also calendarWidget() and calendarPopup.

### QDateTimeEdit.setCurrentSection (self, Section)

### QDateTimeEdit.setCurrentSectionIndex (self, int)

### QDateTimeEdit.setDate (self, QDate)

This method is also a Qt slot with the C++ signature `void setDate(const QDate&)`.

### QDateTimeEdit.setDateRange (self, QDate, QDate)

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().

### QDateTimeEdit.setDateTime (self, QDateTime)

This method is also a Qt slot with the C++ signature `void setDateTime(const QDateTime&)`.

### QDateTimeEdit.setDateTimeRange (self, QDateTime, QDateTime)

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

     setDateTimeRange(min, max);

is analogous to:

     setMinimumDateTime(min);
     setMaximumDateTime(max);

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

This function was introduced in Qt 4.4.

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

### QDateTimeEdit.setDisplayFormat (self, QString)

### QDateTimeEdit.setMaximumDate (self, QDate)

### QDateTimeEdit.setMaximumDateTime (self, QDateTime)

### QDateTimeEdit.setMaximumTime (self, QTime)

### QDateTimeEdit.setMinimumDate (self, QDate)

### QDateTimeEdit.setMinimumDateTime (self, QDateTime)

### QDateTimeEdit.setMinimumTime (self, QTime)

### QDateTimeEdit.setSelectedSection (self, Section)

Selects section. If section doesn't exist in the currently displayed sections this function does nothing. If section is NoSection this function will unselect all text in the editor. Otherwise this function will move the cursor and the current section to the selected section.

This function was introduced in Qt 4.2.

See also currentSection().

### QDateTimeEdit.setTime (self, QTime)

This method is also a Qt slot with the C++ signature `void setTime(const QTime&)`.

### QDateTimeEdit.setTimeRange (self, QTime, QTime)

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().

### QDateTimeEdit.setTimeSpec (self, Qt.TimeSpec)

### QSize QDateTimeEdit.sizeHint (self)

Reimplemented from QWidget.sizeHint().

### QDateTimeEdit.stepBy (self, int)

Reimplemented from QAbstractSpinBox.stepBy().

### QAbstractSpinBox.StepEnabled QDateTimeEdit.stepEnabled (self)

Reimplemented from QAbstractSpinBox.stepEnabled().

### QString QDateTimeEdit.textFromDateTime (self, QDateTime)

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

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

See also dateTimeFromText() and validate().

### QTime QDateTimeEdit.time (self)

### Qt.TimeSpec QDateTimeEdit.timeSpec (self)

### (QValidator.State, QString input, int pos) QDateTimeEdit.validate (self, QString input, int pos)

Reimplemented from QAbstractSpinBox.validate().

### (QValidator.State, int) QDateTimeEdit.validate (self, QString, int)

### QDateTimeEdit.wheelEvent (self, QWheelEvent)

Reimplemented from QWidget.wheelEvent().

## Qt Signal Documentation

### void dateChanged (const QDate&)

This is the default overload of this signal.

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

### void dateTimeChanged (const QDateTime&)

This is the default overload of this signal.

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

### void timeChanged (const QTime&)

This is the default overload of this signal.

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