QDateTimeEdit¶
The
QDateTimeEditclass provides a widget for editing dates and times. More…

Inherited by: QDateEdit, QTimeEdit
Synopsis¶
Functions¶
def
calendar()def
calendarPopup()def
calendarWidget()def
clearMaximumDate()def
clearMaximumDateTime()def
clearMaximumTime()def
clearMinimumDate()def
clearMinimumDateTime()def
clearMinimumTime()def
currentSection()def
currentSectionIndex()def
date()def
dateTime()def
displayFormat()def
displayedSections()def
maximumDate()def
maximumDateTime()def
maximumTime()def
minimumDate()def
minimumDateTime()def
minimumTime()def
sectionAt(index)def
sectionCount()def
sectionText(section)def
setCalendar(calendar)def
setCalendarPopup(enable)def
setCalendarWidget(calendarWidget)def
setCurrentSection(section)def
setCurrentSectionIndex(index)def
setDateRange(min, max)def
setDateTimeRange(min, max)def
setDisplayFormat(format)def
setMaximumDate(max)def
setMaximumDateTime(dt)def
setMaximumTime(max)def
setMinimumDate(min)def
setMinimumDateTime(dt)def
setMinimumTime(min)def
setSelectedSection(section)def
setTimeRange(min, max)def
setTimeSpec(spec)def
time()def
timeSpec()
Virtual functions¶
def
dateTimeFromText(text)def
textFromDateTime(dt)
Slots¶
def
setDate(date)def
setDateTime(dateTime)def
setTime(time)
Signals¶
def
dateChanged(date)def
dateTimeChanged(dateTime)def
timeChanged(time)
Detailed Description¶
![]()
QDateTimeEditallows 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 theQDateTimeEditbox. Dates and times appear in accordance with the format set; seesetDisplayFormat().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
QDateTimeEditobject 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 range of valid values for a
QDateTimeEditis controlled by the propertiesminimumDateTime,maximumDateTime, and their respective date and time components. By default, any date-time from the start of 100 CE to the end of 9999 CE is valid.
Using a Pop-up Calendar Widget¶
QDateTimeEditcan be configured to allow aQCalendarWidgetto be used to select dates. This is enabled by setting thecalendarPopupproperty. Additionally, you can supply a custom calendar widget for use as the calendar pop-up by calling thesetCalendarWidget()function. The existing calendar widget can be retrieved withcalendarWidget().
-
class
QDateTimeEdit([parent=None])¶ QDateTimeEdit(d[, parent=None])
QDateTimeEdit(dt[, parent=None])
QDateTimeEdit(t[, parent=None])
QDateTimeEdit(val, parserType[, parent=None])
- param parent
- 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
See also
-
PySide2.QtWidgets.QDateTimeEdit.calendarWidget()¶ - Return type
Returns the calendar widget for the editor if
calendarPopupis set to true and (sections() &DateSections_Mask) != 0.This function creates and returns a calendar widget if none has been set.
See also
-
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
See also
-
PySide2.QtWidgets.QDateTimeEdit.currentSectionIndex()¶ - Return type
int
See also
-
PySide2.QtWidgets.QDateTimeEdit.date()¶ - Return type
QDate
Returns the date of the date time edit.
See also
-
PySide2.QtWidgets.QDateTimeEdit.dateChanged(date)¶ - Parameters
date –
QDate
-
PySide2.QtWidgets.QDateTimeEdit.dateTime()¶ - Return type
QDateTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.dateTimeChanged(dateTime)¶ - Parameters
dateTime –
QDateTime
-
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
See also
-
PySide2.QtWidgets.QDateTimeEdit.displayedSections()¶ - Return type
Sections
-
PySide2.QtWidgets.QDateTimeEdit.maximumDate()¶ - Return type
QDate
See also
-
PySide2.QtWidgets.QDateTimeEdit.maximumDateTime()¶ - Return type
QDateTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.maximumTime()¶ - Return type
QTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.minimumDate()¶ - Return type
QDate
See also
-
PySide2.QtWidgets.QDateTimeEdit.minimumDateTime()¶ - Return type
QDateTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.minimumTime()¶ - Return type
QTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.sectionAt(index)¶ - Parameters
index –
int- Return type
Returns the Section at
index.If the format is ‘yyyy/MM/dd’, (0) returns
YearSection, (1) returnsMonthSection, and (2) returnsYearSection,
-
PySide2.QtWidgets.QDateTimeEdit.sectionCount()¶ - Return type
int
-
PySide2.QtWidgets.QDateTimeEdit.sectionText(section)¶ - Parameters
section –
Section- Return type
unicode
Returns the text from the given
section.See also
-
PySide2.QtWidgets.QDateTimeEdit.setCalendar(calendar)¶ - Parameters
calendar –
QCalendar
-
PySide2.QtWidgets.QDateTimeEdit.setCalendarPopup(enable)¶ - Parameters
enable –
bool
See also
-
PySide2.QtWidgets.QDateTimeEdit.setCalendarWidget(calendarWidget)¶ - Parameters
calendarWidget –
QCalendarWidget
Sets the given
calendarWidgetas the widget to be used for the calendar pop-up. The editor does not automatically take ownership of the calendar widget.Note
calendarPopupmust be set to true before setting the calendar widget.See also
-
PySide2.QtWidgets.QDateTimeEdit.setCurrentSectionIndex(index)¶ - Parameters
index –
int
See also
-
PySide2.QtWidgets.QDateTimeEdit.setDateRange(min, max)¶ - Parameters
min –
QDatemax –
QDate
Set the range of allowed dates for the date time edit.
This convenience function sets the
minimumDateandmaximumDateproperties.setDateRange(min, max)
is analogous to:
setMinimumDate(min) setMaximumDate(max)
If either
minormaxis invalid, this function does nothing. This function preserves theminimumTimeproperty. Ifmaxis less thanmin, the newmaximumDateTimeproperty shall be the newminimumDateTimeproperty. Ifmaxis equal tominand themaximumTimeproperty was less then theminimumTimeproperty, themaximumTimeproperty is set to theminimumTimeproperty. Otherwise, this preserves themaximumTimeproperty.See also
minimumDatemaximumDatesetDateTimeRange()isValid()
-
PySide2.QtWidgets.QDateTimeEdit.setDateTime(dateTime)¶ - Parameters
dateTime –
QDateTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.setDateTimeRange(min, max)¶ - Parameters
min –
QDateTimemax –
QDateTime
Set the range of allowed date-times for the date time edit.
This convenience function sets the
minimumDateTimeandmaximumDateTimeproperties.setDateTimeRange(min, max)
is analogous to:
setMinimumDateTime(min) setMaximumDateTime(max)
If either
minormaxis invalid, this function does nothing. Ifmaxis less thanmin,minis used also asmax.See also
minimumDateTimemaximumDateTimesetDateRange()setTimeRange()isValid()
-
PySide2.QtWidgets.QDateTimeEdit.setDisplayFormat(format)¶ - Parameters
format – unicode
See also
-
PySide2.QtWidgets.QDateTimeEdit.setMaximumDate(max)¶ - Parameters
max –
QDate
See also
-
PySide2.QtWidgets.QDateTimeEdit.setMaximumDateTime(dt)¶ - Parameters
dt –
QDateTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.setMaximumTime(max)¶ - Parameters
max –
QTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.setMinimumDate(min)¶ - Parameters
min –
QDate
See also
-
PySide2.QtWidgets.QDateTimeEdit.setMinimumDateTime(dt)¶ - Parameters
dt –
QDateTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.setMinimumTime(min)¶ - Parameters
min –
QTime
See also
-
PySide2.QtWidgets.QDateTimeEdit.setSelectedSection(section)¶ - Parameters
section –
Section
Selects
section. Ifsectiondoesn’t exist in the currently displayed sections, this function does nothing. IfsectionisNoSection, 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
-
PySide2.QtWidgets.QDateTimeEdit.setTimeRange(min, max)¶ - Parameters
min –
QTimemax –
QTime
Set the range of allowed times for the date time edit.
This convenience function sets the
minimumTimeandmaximumTimeproperties.Note that these only constrain the date time edit’s value on, respectively, the
minimumDateandmaximumDate. When these date properties do not coincide, times aftermaxare allowed on dates beforemaximumDateand times beforeminare allowed on dates afterminimumDate.setTimeRange(min, max)
is analogous to:
setMinimumTime(min) setMaximumTime(max)
If either
minormaxis invalid, this function does nothing. This function preserves theminimumDateandmaximumDateproperties. If those properties coincide andmaxis less thanmin,minis used asmax.See also
minimumTimemaximumTimesetDateTimeRange()isValid()
-
PySide2.QtWidgets.QDateTimeEdit.setTimeSpec(spec)¶ - Parameters
spec –
TimeSpec
See also
-
PySide2.QtWidgets.QDateTimeEdit.textFromDateTime(dt)¶ - Parameters
dt –
QDateTime- 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
-
PySide2.QtWidgets.QDateTimeEdit.timeChanged(time)¶ - Parameters
time –
QTime
-
PySide2.QtWidgets.QDateTimeEdit.timeSpec()¶ - Return type
TimeSpec
See also
© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.