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

Inherited by: QTimeEdit, QDateEdit
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
dateChanged
(date)def
dateTime
()def
dateTimeChanged
(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
setDate
(date)def
setDateRange
(min, max)def
setDateTime
(dateTime)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
setTime
(time)def
setTimeRange
(min, max)def
setTimeSpec
(spec)def
time
()def
timeChanged
(time)def
timeSpec
()
Virtual functions¶
def
dateTimeFromText
(text)def
textFromDateTime
(dt)
Detailed Description¶
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 range of valid values for a QDateTimeEdit
is controlled by the properties minimumDateTime
, 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¶
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()
.
Keyboard Tracking¶
When keyboard tracking
is enabled (the default), every keystroke of editing a field triggers signals for value changes.
When the allowed range
is narrower than some time interval whose end it straddles, keyboard tracking prevents the user editing the date or time to access the later part of the interval. For example, for a range from 29.04.2020 to 02.05.2020 and an initial date of 30.04.2020, the user can change neither the month (May 30th is outside the range) nor the day (April 2nd is outside the range).
When keyboard tracking is disabled, changes are only signalled when focus leaves the text field after edits have modified the content. This allows the user to edit via an invalid date-time to reach a valid one.
-
class
PySide6.QtWidgets.
QDateTimeEdit
(d[, parent=None])¶ PySide6.QtWidgets.QDateTimeEdit(t[, parent=None])
PySide6.QtWidgets.QDateTimeEdit([parent=None])
PySide6.QtWidgets.QDateTimeEdit(dt[, parent=None])
PySide6.QtWidgets.QDateTimeEdit(val, parserType[, parent=None])
- Parameters
val – object
parserType –
Type
parent –
PySide6.QtWidgets.QWidget
Constructs an empty date time editor with a parent
.
-
PySide6.QtWidgets.QDateTimeEdit.
Section
¶ Constant
Description
QDateTimeEdit.NoSection
QDateTimeEdit.AmPmSection
QDateTimeEdit.MSecSection
QDateTimeEdit.SecondSection
QDateTimeEdit.MinuteSection
QDateTimeEdit.HourSection
QDateTimeEdit.DaySection
QDateTimeEdit.MonthSection
QDateTimeEdit.YearSection
-
PySide6.QtWidgets.QDateTimeEdit.
calendar
()¶ - Return type
-
PySide6.QtWidgets.QDateTimeEdit.
calendarPopup
()¶ - Return type
bool
See also
-
PySide6.QtWidgets.QDateTimeEdit.
calendarWidget
()¶ - Return type
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.
See also
-
PySide6.QtWidgets.QDateTimeEdit.
clearMaximumDate
()¶
-
PySide6.QtWidgets.QDateTimeEdit.
clearMaximumDateTime
()¶
-
PySide6.QtWidgets.QDateTimeEdit.
clearMaximumTime
()¶
-
PySide6.QtWidgets.QDateTimeEdit.
clearMinimumDate
()¶
-
PySide6.QtWidgets.QDateTimeEdit.
clearMinimumDateTime
()¶
-
PySide6.QtWidgets.QDateTimeEdit.
clearMinimumTime
()¶
-
PySide6.QtWidgets.QDateTimeEdit.
currentSection
()¶ - Return type
See also
-
PySide6.QtWidgets.QDateTimeEdit.
currentSectionIndex
()¶ - Return type
int
See also
-
PySide6.QtWidgets.QDateTimeEdit.
date
()¶ - Return type
Returns the date of the date time edit.
See also
-
PySide6.QtWidgets.QDateTimeEdit.
dateChanged
(date)¶ - Parameters
date –
PySide6.QtCore.QDate
-
PySide6.QtWidgets.QDateTimeEdit.
dateTime
()¶ - Return type
See also
-
PySide6.QtWidgets.QDateTimeEdit.
dateTimeChanged
(dateTime)¶ - Parameters
dateTime –
PySide6.QtCore.QDateTime
-
PySide6.QtWidgets.QDateTimeEdit.
dateTimeFromText
(text)¶ - Parameters
text – str
- Return type
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()
-
PySide6.QtWidgets.QDateTimeEdit.
displayFormat
()¶ - Return type
str
See also
-
PySide6.QtWidgets.QDateTimeEdit.
displayedSections
()¶ - Return type
Sections
-
PySide6.QtWidgets.QDateTimeEdit.
maximumDate
()¶ - Return type
See also
-
PySide6.QtWidgets.QDateTimeEdit.
maximumDateTime
()¶ - Return type
See also
-
PySide6.QtWidgets.QDateTimeEdit.
maximumTime
()¶ - Return type
See also
-
PySide6.QtWidgets.QDateTimeEdit.
minimumDate
()¶ - Return type
See also
-
PySide6.QtWidgets.QDateTimeEdit.
minimumDateTime
()¶ - Return type
See also
-
PySide6.QtWidgets.QDateTimeEdit.
minimumTime
()¶ - Return type
See also
Returns the Section at index
.
If the format is ‘yyyy/MM/dd’, (0) returns YearSection
, (1) returns MonthSection
, and (2) returns YearSection
,
-
PySide6.QtWidgets.QDateTimeEdit.
sectionCount
()¶ - Return type
int
-
PySide6.QtWidgets.QDateTimeEdit.
setCalendar
(calendar)¶ - Parameters
calendar –
PySide6.QtCore.QCalendar
-
PySide6.QtWidgets.QDateTimeEdit.
setCalendarPopup
(enable)¶ - Parameters
enable – bool
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setCalendarWidget
(calendarWidget)¶ - Parameters
calendarWidget –
PySide6.QtWidgets.QCalendarWidget
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.
-
PySide6.QtWidgets.QDateTimeEdit.
setCurrentSectionIndex
(index)¶ - Parameters
index – int
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setDate
(date)¶ - Parameters
date –
PySide6.QtCore.QDate
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setDateRange
(min, max)¶ - Parameters
min –
PySide6.QtCore.QDate
max –
PySide6.QtCore.QDate
Set the range of allowed dates for the date time edit.
This convenience function sets the minimumDate
and maximumDate
properties.
setDateRange(min, max)
is analogous to:
setMinimumDate(min) setMaximumDate(max)
If either min
or max
is invalid, this function does nothing. This function preserves the minimumTime
property. If max
is less than min
, the new maximumDateTime
property shall be the new minimumDateTime
property. If max
is equal to min
and the maximumTime
property was less then the minimumTime
property, the maximumTime
property is set to the minimumTime
property. Otherwise, this preserves the maximumTime
property.
If the range is narrower then a time interval whose end it spans, for example a week that spans the end of a month, users can only edit the date to one in the later part of the range if keyboard-tracking is disabled.
See also
minimumDate
maximumDate
setDateTimeRange()
isValid()
Keyboard Tracking
-
PySide6.QtWidgets.QDateTimeEdit.
setDateTime
(dateTime)¶ - Parameters
dateTime –
PySide6.QtCore.QDateTime
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setDateTimeRange
(min, max)¶ - Parameters
min –
PySide6.QtCore.QDateTime
max –
PySide6.QtCore.QDateTime
Set the range of allowed date-times for the date time edit.
This convenience function sets the minimumDateTime
and maximumDateTime
properties.
setDateTimeRange(min, max)
is analogous to:
setMinimumDateTime(min) setMaximumDateTime(max)
If either min
or max
is invalid, this function does nothing. If max
is less than min
, min
is used also as max
.
If the range is narrower then a time interval whose end it spans, for example a week that spans the end of a month, users can only edit the date-time to one in the later part of the range if keyboard-tracking is disabled.
See also
minimumDateTime
maximumDateTime
setDateRange()
setTimeRange()
isValid()
Keyboard Tracking
-
PySide6.QtWidgets.QDateTimeEdit.
setDisplayFormat
(format)¶ - Parameters
format – str
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setMaximumDate
(max)¶ - Parameters
max –
PySide6.QtCore.QDate
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setMaximumDateTime
(dt)¶ - Parameters
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setMaximumTime
(max)¶ - Parameters
max –
PySide6.QtCore.QTime
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setMinimumDate
(min)¶ - Parameters
min –
PySide6.QtCore.QDate
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setMinimumDateTime
(dt)¶ - Parameters
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setMinimumTime
(min)¶ - Parameters
min –
PySide6.QtCore.QTime
See also
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
-
PySide6.QtWidgets.QDateTimeEdit.
setTime
(time)¶ - Parameters
time –
PySide6.QtCore.QTime
See also
-
PySide6.QtWidgets.QDateTimeEdit.
setTimeRange
(min, max)¶ - Parameters
min –
PySide6.QtCore.QTime
max –
PySide6.QtCore.QTime
Set the range of allowed times for the date time edit.
This convenience function sets the minimumTime
and maximumTime
properties.
Note that these only constrain the date time edit’s value on, respectively, the minimumDate
and maximumDate
. When these date properties do not coincide, times after max
are allowed on dates before maximumDate
and times before min
are allowed on dates after minimumDate
.
setTimeRange(min, max)
is analogous to:
setMinimumTime(min) setMaximumTime(max)
If either min
or max
is invalid, this function does nothing. This function preserves the minimumDate
and maximumDate
properties. If those properties coincide and max
is less than min
, min
is used as max
.
If the range is narrower then a time interval whose end it spans, for example the interval from ten to an hour to ten past the same hour, users can only edit the time to one in the later part of the range if keyboard-tracking is disabled.
See also
minimumTime
maximumTime
setDateTimeRange()
isValid()
Keyboard Tracking
-
PySide6.QtWidgets.QDateTimeEdit.
textFromDateTime
(dt)¶ - Parameters
- Return type
str
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()
-
PySide6.QtWidgets.QDateTimeEdit.
time
()¶ - Return type
Returns the time of the date time edit.
See also
-
PySide6.QtWidgets.QDateTimeEdit.
timeChanged
(time)¶ - Parameters
time –
PySide6.QtCore.QTime
-
PySide6.QtWidgets.QDateTimeEdit.
timeSpec
()¶ - Return type
See also
© 2021 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.