QDateTimeEdit

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

Inheritance diagram of PySide2.QtWidgets.QDateTimeEdit

Inherited by: QDateEdit, QTimeEdit

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

../../_images/windows-datetimeedit.png

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

dateEdit = 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. You can change this by calling setMinimumDate() , taking into account that the minimum value for QDate is 2 January 4713BC.

Other useful functions are 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() .

class QDateTimeEdit([parent=None])

QDateTimeEdit(d[, parent=None])

QDateTimeEdit(dt[, parent=None])

QDateTimeEdit(t[, parent=None])

QDateTimeEdit(val, parserType[, parent=None])

param parent

QWidget

param dt

QDateTime

param val

object

param parserType

QVariant::Type

param t

QTime

param d

QDate

Constructs an empty date time editor with a parent .

PySide2.QtWidgets.QDateTimeEdit.Section

Constant

Description

QDateTimeEdit.NoSection

QDateTimeEdit.AmPmSection

QDateTimeEdit.MSecSection

QDateTimeEdit.SecondSection

QDateTimeEdit.MinuteSection

QDateTimeEdit.HourSection

QDateTimeEdit.DaySection

QDateTimeEdit.MonthSection

QDateTimeEdit.YearSection

PySide2.QtWidgets.QDateTimeEdit.calendar()
Return type

QCalendar

PySide2.QtWidgets.QDateTimeEdit.calendarPopup()
Return type

bool

PySide2.QtWidgets.QDateTimeEdit.calendarWidget()
Return type

QCalendarWidget

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.

PySide2.QtWidgets.QDateTimeEdit.clearMaximumDate()
PySide2.QtWidgets.QDateTimeEdit.clearMaximumDateTime()
PySide2.QtWidgets.QDateTimeEdit.clearMaximumTime()
PySide2.QtWidgets.QDateTimeEdit.clearMinimumDate()
PySide2.QtWidgets.QDateTimeEdit.clearMinimumDateTime()
PySide2.QtWidgets.QDateTimeEdit.clearMinimumTime()
PySide2.QtWidgets.QDateTimeEdit.currentSection()
Return type

Section

PySide2.QtWidgets.QDateTimeEdit.currentSectionIndex()
Return type

int

PySide2.QtWidgets.QDateTimeEdit.date()
Return type

QDate

Returns the date of the date time edit.

See also

setDate()

PySide2.QtWidgets.QDateTimeEdit.dateChanged(date)
Parameters

dateQDate

PySide2.QtWidgets.QDateTimeEdit.dateTime()
Return type

QDateTime

See also

setDateTime()

PySide2.QtWidgets.QDateTimeEdit.dateTimeChanged(dateTime)
Parameters

dateTimeQDateTime

PySide2.QtWidgets.QDateTimeEdit.dateTimeFromText(text)
Parameters

text – unicode

Return type

QDateTime

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

PySide2.QtWidgets.QDateTimeEdit.displayFormat()
Return type

unicode

PySide2.QtWidgets.QDateTimeEdit.displayedSections()
Return type

Sections

PySide2.QtWidgets.QDateTimeEdit.maximumDate()
Return type

QDate

See also

setMaximumDate()

PySide2.QtWidgets.QDateTimeEdit.maximumDateTime()
Return type

QDateTime

PySide2.QtWidgets.QDateTimeEdit.maximumTime()
Return type

QTime

See also

setMaximumTime()

PySide2.QtWidgets.QDateTimeEdit.minimumDate()
Return type

QDate

See also

setMinimumDate()

PySide2.QtWidgets.QDateTimeEdit.minimumDateTime()
Return type

QDateTime

PySide2.QtWidgets.QDateTimeEdit.minimumTime()
Return type

QTime

See also

setMinimumTime()

PySide2.QtWidgets.QDateTimeEdit.sectionAt(index)
Parameters

indexint

Return type

Section

Returns the Section at index .

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

PySide2.QtWidgets.QDateTimeEdit.sectionCount()
Return type

int

PySide2.QtWidgets.QDateTimeEdit.sectionText(section)
Parameters

sectionSection

Return type

unicode

Returns the text from the given section .

See also

currentSection()

PySide2.QtWidgets.QDateTimeEdit.setCalendar(calendar)
Parameters

calendarQCalendar

PySide2.QtWidgets.QDateTimeEdit.setCalendarPopup(enable)
Parameters

enablebool

See also

calendarPopup()

PySide2.QtWidgets.QDateTimeEdit.setCalendarWidget(calendarWidget)
Parameters

calendarWidgetQCalendarWidget

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.

Note

calendarPopup must be set to true before setting the calendar widget.

PySide2.QtWidgets.QDateTimeEdit.setCurrentSection(section)
Parameters

sectionSection

See also

currentSection()

PySide2.QtWidgets.QDateTimeEdit.setCurrentSectionIndex(index)
Parameters

indexint

PySide2.QtWidgets.QDateTimeEdit.setDate(date)
Parameters

dateQDate

See also

date()

PySide2.QtWidgets.QDateTimeEdit.setDateRange(min, max)
Parameters
  • minQDate

  • maxQDate

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.

PySide2.QtWidgets.QDateTimeEdit.setDateTime(dateTime)
Parameters

dateTimeQDateTime

See also

dateTime()

PySide2.QtWidgets.QDateTimeEdit.setDateTimeRange(min, max)
Parameters
  • minQDateTime

  • maxQDateTime

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.

PySide2.QtWidgets.QDateTimeEdit.setDisplayFormat(format)
Parameters

format – unicode

See also

displayFormat()

PySide2.QtWidgets.QDateTimeEdit.setMaximumDate(max)
Parameters

maxQDate

See also

maximumDate()

PySide2.QtWidgets.QDateTimeEdit.setMaximumDateTime(dt)
Parameters

dtQDateTime

PySide2.QtWidgets.QDateTimeEdit.setMaximumTime(max)
Parameters

maxQTime

See also

maximumTime()

PySide2.QtWidgets.QDateTimeEdit.setMinimumDate(min)
Parameters

minQDate

See also

minimumDate()

PySide2.QtWidgets.QDateTimeEdit.setMinimumDateTime(dt)
Parameters

dtQDateTime

PySide2.QtWidgets.QDateTimeEdit.setMinimumTime(min)
Parameters

minQTime

See also

minimumTime()

PySide2.QtWidgets.QDateTimeEdit.setSelectedSection(section)
Parameters

sectionSection

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.

See also

currentSection()

PySide2.QtWidgets.QDateTimeEdit.setTime(time)
Parameters

timeQTime

See also

time()

PySide2.QtWidgets.QDateTimeEdit.setTimeRange(min, max)
Parameters
  • minQTime

  • maxQTime

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.

PySide2.QtWidgets.QDateTimeEdit.setTimeSpec(spec)
Parameters

specTimeSpec

See also

timeSpec()

PySide2.QtWidgets.QDateTimeEdit.textFromDateTime(dt)
Parameters

dtQDateTime

Return type

unicode

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

PySide2.QtWidgets.QDateTimeEdit.time()
Return type

QTime

Returns the time of the date time edit.

See also

setTime()

PySide2.QtWidgets.QDateTimeEdit.timeChanged(time)
Parameters

timeQTime

PySide2.QtWidgets.QDateTimeEdit.timeSpec()
Return type

TimeSpec

See also

setTimeSpec()