QDateTimeEdit

Inheritance diagram of PySide2.QtWidgets.QDateTimeEdit

Inherited by: QDateEdit, QTimeEdit

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

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

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

PySide2.QtWidgets.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 PySide2.QtWidgets.QDateTimeEdit box. Dates and times appear in accordance with the format set; see PySide2.QtWidgets.QDateTimeEdit.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 PySide2.QtWidgets.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 PySide2.QtWidgets.QDateTimeEdit is 14 September 1752. You can change this by calling PySide2.QtWidgets.QDateTimeEdit.setMinimumDate() , taking into account that the minimum value for PySide2.QtCore.QDate is 2 January 4713BC.

Other useful functions are PySide2.QtWidgets.QDateTimeEdit.setMaximumDate() , PySide2.QtWidgets.QDateTimeEdit.setMinimumTime() and PySide2.QtWidgets.QDateTimeEdit.setMaximumTime() .

Using a Pop-up Calendar Widget

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

class PySide2.QtWidgets.QDateTimeEdit([parent=nullptr])
class PySide2.QtWidgets.QDateTimeEdit(d[, parent=nullptr])
class PySide2.QtWidgets.QDateTimeEdit(dt[, parent=nullptr])
class PySide2.QtWidgets.QDateTimeEdit(t[, parent=nullptr])
class PySide2.QtWidgets.QDateTimeEdit(val, parserType[, parent=nullptr])
Parameters:

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 datetime .

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

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.calendarPopup()
Return type:PySide2.QtCore.bool
PySide2.QtWidgets.QDateTimeEdit.calendarWidget()
Return type:PySide2.QtWidgets.QCalendarWidget

Returns the calendar widget for the editor if PySide2.QtWidgets.QDateTimeEdit.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:PySide2.QtWidgets.QDateTimeEdit.Section
PySide2.QtWidgets.QDateTimeEdit.currentSectionIndex()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QDateTimeEdit.date()
Return type:PySide2.QtCore.QDate

Returns the date of the date time edit.

PySide2.QtWidgets.QDateTimeEdit.dateChanged(date)
Parameters:datePySide2.QtCore.QDate
PySide2.QtWidgets.QDateTimeEdit.dateTime()
Return type:PySide2.QtCore.QDateTime
PySide2.QtWidgets.QDateTimeEdit.dateTimeChanged(dateTime)
Parameters:dateTimePySide2.QtCore.QDateTime
PySide2.QtWidgets.QDateTimeEdit.dateTimeFromText(text)
Parameters:text – unicode
Return type:PySide2.QtCore.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

PySide2.QtWidgets.QDateTimeEdit.textFromDateTime() PySide2.QtWidgets.QDateTimeEdit.validate()

PySide2.QtWidgets.QDateTimeEdit.displayFormat()
Return type:unicode
PySide2.QtWidgets.QDateTimeEdit.displayedSections()
Return type:PySide2.QtWidgets.QDateTimeEdit.Sections
PySide2.QtWidgets.QDateTimeEdit.maximumDate()
Return type:PySide2.QtCore.QDate
PySide2.QtWidgets.QDateTimeEdit.maximumDateTime()
Return type:PySide2.QtCore.QDateTime
PySide2.QtWidgets.QDateTimeEdit.maximumTime()
Return type:PySide2.QtCore.QTime
PySide2.QtWidgets.QDateTimeEdit.minimumDate()
Return type:PySide2.QtCore.QDate
PySide2.QtWidgets.QDateTimeEdit.minimumDateTime()
Return type:PySide2.QtCore.QDateTime
PySide2.QtWidgets.QDateTimeEdit.minimumTime()
Return type:PySide2.QtCore.QTime
PySide2.QtWidgets.QDateTimeEdit.sectionAt(index)
Parameters:indexPySide2.QtCore.int
Return type:PySide2.QtWidgets.QDateTimeEdit.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:PySide2.QtCore.int
PySide2.QtWidgets.QDateTimeEdit.sectionText(section)
Parameters:sectionPySide2.QtWidgets.QDateTimeEdit.Section
Return type:unicode

Returns the text from the given section .

PySide2.QtWidgets.QDateTimeEdit.setCalendarPopup(enable)
Parameters:enablePySide2.QtCore.bool
PySide2.QtWidgets.QDateTimeEdit.setCalendarWidget(calendarWidget)
Parameters:calendarWidgetPySide2.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.

Note

PySide2.QtWidgets.QDateTimeEdit.calendarPopup() must be set to true before setting the calendar widget.

PySide2.QtWidgets.QDateTimeEdit.setCurrentSection(section)
Parameters:sectionPySide2.QtWidgets.QDateTimeEdit.Section
PySide2.QtWidgets.QDateTimeEdit.setCurrentSectionIndex(index)
Parameters:indexPySide2.QtCore.int
PySide2.QtWidgets.QDateTimeEdit.setDate(date)
Parameters:datePySide2.QtCore.QDate
PySide2.QtWidgets.QDateTimeEdit.setDateRange(min, max)
Parameters:

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:dateTimePySide2.QtCore.QDateTime
PySide2.QtWidgets.QDateTimeEdit.setDateTimeRange(min, max)
Parameters:

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
PySide2.QtWidgets.QDateTimeEdit.setMaximumDate(max)
Parameters:maxPySide2.QtCore.QDate
PySide2.QtWidgets.QDateTimeEdit.setMaximumDateTime(dt)
Parameters:dtPySide2.QtCore.QDateTime
PySide2.QtWidgets.QDateTimeEdit.setMaximumTime(max)
Parameters:maxPySide2.QtCore.QTime
PySide2.QtWidgets.QDateTimeEdit.setMinimumDate(min)
Parameters:minPySide2.QtCore.QDate
PySide2.QtWidgets.QDateTimeEdit.setMinimumDateTime(dt)
Parameters:dtPySide2.QtCore.QDateTime
PySide2.QtWidgets.QDateTimeEdit.setMinimumTime(min)
Parameters:minPySide2.QtCore.QTime
PySide2.QtWidgets.QDateTimeEdit.setSelectedSection(section)
Parameters:sectionPySide2.QtWidgets.QDateTimeEdit.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.

PySide2.QtWidgets.QDateTimeEdit.setTime(time)
Parameters:timePySide2.QtCore.QTime
PySide2.QtWidgets.QDateTimeEdit.setTimeRange(min, max)
Parameters:

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:specPySide2.QtCore.Qt.TimeSpec
PySide2.QtWidgets.QDateTimeEdit.textFromDateTime(dt)
Parameters:dtPySide2.QtCore.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 PySide2.QtWidgets.QDateTimeEdit.validate() .

See also

PySide2.QtWidgets.QDateTimeEdit.dateTimeFromText() PySide2.QtWidgets.QDateTimeEdit.validate()

PySide2.QtWidgets.QDateTimeEdit.time()
Return type:PySide2.QtCore.QTime

Returns the time of the date time edit.

PySide2.QtWidgets.QDateTimeEdit.timeChanged(time)
Parameters:timePySide2.QtCore.QTime
PySide2.QtWidgets.QDateTimeEdit.timeSpec()
Return type:PySide2.QtCore.Qt.TimeSpec