PySide6.QtWidgets.QDateTimeEdit¶
- class QDateTimeEdit¶
- The - QDateTimeEditclass provides a widget for editing dates and times. More…- Inherited by: - QTimeEdit,- QDateEdit- Synopsis¶- Properties¶- calendarPopupᅟ- Current calendar pop-up show mode
- currentSectionᅟ- Current section of the spinbox
- currentSectionIndexᅟ- Current section index of the spinbox
- dateᅟ- QDate that is set in the widget
- dateTimeᅟ- QDateTime that is set in the QDateTimeEdit
- displayFormatᅟ- Format used to display the time/date of the date time edit
- displayedSectionsᅟ- Currently displayed fields of the date time edit
- maximumDateᅟ- Maximum date of the date time edit
- maximumDateTimeᅟ- Maximum datetime of the date time edit
- maximumTimeᅟ- Maximum time of the date time edit
- minimumDateᅟ- Minimum date of the date time edit
- minimumDateTimeᅟ- Minimum datetime of the date time edit
- minimumTimeᅟ- Minimum time of the date time edit
- sectionCountᅟ- Number of sections displayed. If the format is ‘yyyy/yy/yyyy’, sectionCount returns 3
- timeᅟ- QTime that is set in the widget
- timeSpecᅟ- Current timespec used by the date time edit
- timeZoneᅟ- Current timezone used by the datetime editing widget
 - Methods¶- def - __init__()
- def - calendar()
- def - calendarPopup()
- def - calendarWidget()
- def - currentSection()
- def - date()
- def - dateTime()
- def - displayFormat()
- def - maximumDate()
- def - maximumTime()
- def - minimumDate()
- def - minimumTime()
- def - sectionAt()
- def - sectionCount()
- def - sectionText()
- def - setCalendar()
- def - setDateRange()
- def - setMaximumDate()
- def - setMaximumTime()
- def - setMinimumDate()
- def - setMinimumTime()
- def - setTimeRange()
- def - setTimeSpec()
- def - setTimeZone()
- def - time()
- def - timeSpec()
- def - timeZone()
 - Virtual methods¶- Slots¶- def - setDate()
- def - setDateTime()
- def - setTime()
 - Signals¶- def - dateChanged()
- def - timeChanged()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors.   - 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 the- QDateTimeEditbox. 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 - 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 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¶- QDateTimeEditcan be configured to allow a- QCalendarWidgetto be used to select dates. This is enabled by setting the- calendarPopupproperty. 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 trackingis enabled (the default), every keystroke of editing a field triggers signals for value changes.- When the allowed - rangeis 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 Section¶
- Constant - Description - QDateTimeEdit.NoSection - QDateTimeEdit.AmPmSection - QDateTimeEdit.MSecSection - QDateTimeEdit.SecondSection - QDateTimeEdit.MinuteSection - QDateTimeEdit.HourSection - QDateTimeEdit.DaySection - QDateTimeEdit.MonthSection - QDateTimeEdit.YearSection 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property calendarPopupᅟ: bool¶
 - This property holds The current calendar pop-up show mode.. - The calendar pop-up will be shown upon clicking the arrow button. This property is valid only if there is a valid date display format. - See also - Access functions:
 - property currentSectionᅟ: QDateTimeEdit.Section¶
 - This property holds The current section of the spinbox.. - Access functions:
 - property currentSectionIndexᅟ: int¶
 - This property holds The current section index of the spinbox.. - If the format is ‘yyyy/MM/dd’, the displayText is ‘2001/05/21’, and the cursorPosition is 5, currentSectionIndex returns 1. If the cursorPosition is 3, currentSectionIndex is 0, and so on. - See also - Access functions:
 - This property holds The QDate that is set in the widget.. - By default, this property contains a date that refers to January 1, 2000. - Access functions:
- Signal - dateChanged()
 
 - This property holds The QDateTime that is set in the - QDateTimeEdit..- When setting this property, the new QDateTime is converted to the time system of the - QDateTimeEdit, which thus remains unchanged.- By default, this property is set to the start of 2000 CE. It can only be set to a valid QDateTime value. If any operation causes this property to have an invalid date-time as value, it is reset to the value of the - minimumDateTimeproperty.- If the - QDateTimeEdithas no date fields, setting this property sets the widget’s date-range to start and end on the date of the new value of this property.- See also - Access functions:
 - property displayFormatᅟ: str¶
 - This property holds The format used to display the time/date of the date time edit.. - This format is described in QDateTime::toString() and QDateTime::fromString() - Example format strings (assuming that the date is 2nd of July 1969): - Format - Result - dd.MM.yyyy - 02.07.1969 - MMM d yy - Jul 2 69 - MMMM d yy - July 2 69 - Note that if you specify a two digit year, it will be interpreted to be in the century in which the date time edit was initialized. The default century is the 21st (2000-2099). - If you specify an invalid format the format will not be set. - See also - Access functions:
 - property displayedSectionsᅟ: Combination of QDateTimeEdit.Section¶
 - This property holds The currently displayed fields of the date time edit.. - Returns a bit set of the displayed sections for this format. - See also - Access functions:
 - This property holds The maximum date of the date time edit.. - Changing this property updates the date of the - maximumDateTimeproperty while preserving the- maximumTimeproperty. When setting this property, the- minimumDateis adjusted, if necessary, to ensure that the range remains valid. When this happens, the- minimumTimeproperty is also adjusted if it is greater than the- maximumTimeproperty. Otherwise, changes to this property preserve the- minimumDateTimeproperty.- This property can only be set to a valid QDate object describing a date on which the current - maximumTimeproperty makes a valid QDateTime object. The latest date that setMaximumDate() accepts is the end of 9999 CE. This is the default for this property. This default can be restored with- clearMaximumDateTime().- See also - minimumDate- maximumTime- maximumDateTime- setDateRange()- Keyboard Tracking- Access functions:
 - This property holds The maximum datetime of the date time edit.. - Changing this property implicitly updates the - maximumDateand- maximumTimeproperties to the date and time parts of this property, respectively. When setting this property, the- minimumDateTimeis adjusted, if necessary, to ensure that the range remains valid. Otherwise, changing this property preserves the- minimumDateTimeproperty.- This property can only be set to a valid QDateTime value. The latest date-time that setMaximumDateTime() accepts is the end of 9999 CE. This is the default for this property. This default can be restored with clearMaximumDateTime(). - See also - minimumDateTime- maximumTime- maximumDate()- setDateTimeRange()- Keyboard Tracking- Access functions:
 - This property holds The maximum time of the date time edit.. - Changing this property updates the time of the - maximumDateTimeproperty while preserving the- minimumDateand- maximumDateproperties. If those date properties coincide, when setting this property, the- minimumTimeproperty is adjusted, if necessary, to ensure that the range remains valid. Otherwise, changing this property preserves the- minimumDateTimeproperty.- This property can be set to any valid QTime value. By default, this property contains a time of 23:59:59 and 999 milliseconds. This default can be restored with clearMaximumTime(). - See also - minimumTime- maximumDate- maximumDateTime- setTimeRange()- Keyboard Tracking- Access functions:
 - This property holds The minimum date of the date time edit.. - Changing this property updates the date of the - minimumDateTimeproperty while preserving the- minimumTimeproperty. When setting this property, the- maximumDateis adjusted, if necessary, to ensure that the range remains valid. When this happens, the- maximumTimeproperty is also adjusted if it is less than the- minimumTimeproperty. Otherwise, changes to this property preserve the- maximumDateTimeproperty.- This property can only be set to a valid QDate object describing a date on which the current - minimumTimeproperty makes a valid QDateTime object. The earliest date that setMinimumDate() accepts is the start of 100 CE. The default for this property is September 14, 1752 CE. This default can be restored with- clearMinimumDateTime().- See also - maximumDate- minimumTime- minimumDateTime- setDateRange()- Keyboard Tracking- Access functions:
 - This property holds The minimum datetime of the date time edit.. - Changing this property implicitly updates the - minimumDateand- minimumTimeproperties to the date and time parts of this property, respectively. When setting this property, the- maximumDateTimeis adjusted, if necessary, to ensure that the range remains valid. Otherwise, changing this property preserves the- maximumDateTimeproperty.- This property can only be set to a valid QDateTime value. The earliest date-time that setMinimumDateTime() accepts is the start of 100 CE. The property’s default is the start of September 14, 1752 CE. This default can be restored with clearMinimumDateTime(). - See also - maximumDateTime- minimumTime- minimumDate- setDateTimeRange()- Keyboard Tracking- Access functions:
 - This property holds The minimum time of the date time edit.. - Changing this property updates the time of the - minimumDateTimeproperty while preserving the- minimumDateand- maximumDateproperties. If those date properties coincide, when setting this property, the- maximumTimeproperty is adjusted, if necessary, to ensure that the range remains valid. Otherwise, changing this property preserves the- maximumDateTimeproperty.- This property can be set to any valid QTime value. By default, this property contains a time of 00:00:00 and 0 milliseconds. This default can be restored with clearMinimumTime(). - See also - maximumTime- minimumDate- minimumDateTime- setTimeRange()- Keyboard Tracking- Access functions:
 - property sectionCountᅟ: int¶
 - This property holds The number of sections displayed. If the format is ‘yyyy/yy/yyyy’, sectionCount returns 3. - Access functions:
 - This property holds The QTime that is set in the widget.. - By default, this property contains a time of 00:00:00 and 0 milliseconds. - Access functions:
- Signal - timeChanged()
 
 - property timeSpecᅟ: Qt.TimeSpec¶
 - Use - timeZoneinstead.- This property holds The current timespec used by the date time edit.. - Since Qt 6.7 this is an indirect accessor for the - timeZoneproperty.- See also - Access functions:
 - This property holds The current timezone used by the datetime editing widget. - If the datetime format in use includes a timezone indicator - that is, a - t,- tt,- tttor- ttttformat specifier - the user’s input is re-expressed in this timezone whenever it is parsed, overriding any timezone the user may have specified.- See also - Access functions:
 - Constructs an empty date time editor with a - parent.- Constructs an empty date time editor with a - parent. The value is set to- date.- Constructs an empty date time editor with a - parent. The value is set to- time.- Constructs an empty date time editor with a - parent. The value is set to- datetime.- __init__(val, parserType[, parent=None])
 - Report the calendar system in use by this widget. - See also - calendarPopup()¶
- Return type:
- bool 
 - See also 
 - Getter of property - calendarPopupᅟ.- 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 - clearMaximumDate()¶
 - Reset function of property - maximumDateᅟ.- clearMaximumDateTime()¶
 - Reset function of property - maximumDateTimeᅟ.- clearMaximumTime()¶
 - Reset function of property - maximumTimeᅟ.- clearMinimumDate()¶
 - Reset function of property - minimumDateᅟ.- clearMinimumDateTime()¶
 - Reset function of property - minimumDateTimeᅟ.- clearMinimumTime()¶
 - Reset function of property - minimumTimeᅟ.- currentSection()¶
- Return type:
 - See also 
 - Getter of property - currentSectionᅟ.- currentSectionIndex()¶
- Return type:
- int 
 - See also 
 - Getter of property - currentSectionIndexᅟ.- Returns the date of the date time edit. - See also - Getter of property - dateᅟ.- This signal is emitted whenever the date is changed. The new date is passed in - date.- See also - Keyboard Tracking- Notification signal of property - dateᅟ.- dateTime()¶
- Return type:
 - See also 
 - Getter of property - dateTimeᅟ.- This signal is emitted whenever the date or time is changed. The new date and time is passed in - datetime.- See also - Keyboard Tracking- Notification signal of property - dateTimeᅟ.- 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()- displayFormat()¶
- Return type:
- str 
 - See also 
 - Getter of property - displayFormatᅟ.- Getter of property - displayedSectionsᅟ.- maximumDate()¶
- Return type:
 - See also 
 - Getter of property - maximumDateᅟ.- maximumDateTime()¶
- Return type:
 - See also 
 - Getter of property - maximumDateTimeᅟ.- maximumTime()¶
- Return type:
 - See also 
 - Getter of property - maximumTimeᅟ.- minimumDate()¶
- Return type:
 - See also 
 - Getter of property - minimumDateᅟ.- minimumDateTime()¶
- Return type:
 - See also 
 - Getter of property - minimumDateTimeᅟ.- minimumTime()¶
- Return type:
 - See also 
 - Getter of property - minimumTimeᅟ.- 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,- sectionCount()¶
- Return type:
- int 
 
 - Getter of property - sectionCountᅟ.- Returns the text from the given - section.- See also - Set - calendaras the calendar system to be used by this widget.- The widget can use any supported calendar system. By default, it uses the Gregorian calendar. - See also - setCalendarPopup(enable)¶
- Parameters:
- enable – bool 
 - See also 
 - Setter of property - calendarPopupᅟ.- 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.- Setter of property - currentSectionᅟ.- setCurrentSectionIndex(index)¶
- Parameters:
- index – int 
 - See also 
 - Setter of property - currentSectionIndexᅟ.- Setter of property - dateᅟ.- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Set the range of allowed dates for the date time edit. - This convenience function sets the - minimumDateand- maximumDateproperties.- setDateRange(min, max) - is analogous to: - setMinimumDate(min) setMaximumDate(max) - If either - minor- maxis invalid, this function does nothing. This function preserves the- minimumTimeproperty. If- maxis less than- min, the new- maximumDateTimeproperty shall be the new- minimumDateTimeproperty. If- maxis equal to- minand the- maximumTimeproperty was less then the- minimumTimeproperty, the- maximumTimeproperty is set to the- minimumTimeproperty. Otherwise, this preserves the- maximumTimeproperty.- 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()- Keyboard Tracking- Setter of property - dateTimeᅟ.- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Set the range of allowed date-times for the date time edit. - This convenience function sets the - minimumDateTimeand- maximumDateTimeproperties.- setDateTimeRange(min, max) - is analogous to: - setMinimumDateTime(min) setMaximumDateTime(max) - If either - minor- maxis invalid, this function does nothing. If- maxis less than- min,- minis 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()- Keyboard Tracking- setDisplayFormat(format)¶
- Parameters:
- format – str 
 - See also 
 - Setter of property - displayFormatᅟ.- Setter of property - maximumDateᅟ.- Setter of property - maximumDateTimeᅟ.- Setter of property - maximumTimeᅟ.- Setter of property - minimumDateᅟ.- Setter of property - minimumDateTimeᅟ.- Setter of property - minimumTimeᅟ.- Selects - section. If- sectiondoesn’t exist in the currently displayed sections, this function does nothing. If- sectionis- 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 - Setter of property - timeᅟ.- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Set the range of allowed times for the date time edit. - This convenience function sets the - minimumTimeand- maximumTimeproperties.- Note that these only constrain the date time edit’s value on, respectively, the - minimumDateand- maximumDate. When these date properties do not coincide, times after- maxare allowed on dates before- maximumDateand times before- minare allowed on dates after- minimumDate.- setTimeRange(min, max) - is analogous to: - setMinimumTime(min) setMaximumTime(max) - If either - minor- maxis invalid, this function does nothing. This function preserves the- minimumDateand- maximumDateproperties. If those properties coincide and- maxis less than- min,- minis 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()- Keyboard Tracking- Setter of property - timeSpecᅟ.- Setter of property - timeZoneᅟ.- 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()- Returns the time of the date time edit. - See also - Getter of property - timeᅟ.- This signal is emitted whenever the time is changed. The new time is passed in - time.- See also - Keyboard Tracking- Notification signal of property - timeᅟ.- timeSpec()¶
- Return type:
 - Note - This function is deprecated. - See also 
 - Getter of property - timeSpecᅟ.- timeZone()¶
- Return type:
 - See also 
 - Getter of property - timeZoneᅟ.