内容表

上一话题

QDateEdit

下一话题

QDesktopWidget

QDateTimeEdit

QDateTimeEdit class provides a widget for editing dates and times. 更多

Inheritance diagram of PySide2.QtWidgets.QDateTimeEdit

继承者: QDateEdit , QTimeEdit

详细描述

../../_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 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.

使用弹出日历 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

构造空的日期时间编辑器采用 parent .

PySide2.QtWidgets.QDateTimeEdit. Section

常量

描述

QDateTimeEdit.NoSection

QDateTimeEdit.AmPmSection

QDateTimeEdit.MSecSection

QDateTimeEdit.SecondSection

QDateTimeEdit.MinuteSection

QDateTimeEdit.HourSection

QDateTimeEdit.DaySection

QDateTimeEdit.MonthSection

QDateTimeEdit.YearSection

PySide2.QtWidgets.QDateTimeEdit. calendar ( )
返回类型

QCalendar

PySide2.QtWidgets.QDateTimeEdit. calendarPopup ( )
返回类型

bool

PySide2.QtWidgets.QDateTimeEdit. calendarWidget ( )
返回类型

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 ( )
返回类型

Section

PySide2.QtWidgets.QDateTimeEdit. currentSectionIndex ( )
返回类型

int

PySide2.QtWidgets.QDateTimeEdit. date ( )
返回类型

QDate

返回日期时间编辑的日期。

另请参阅

setDate()

PySide2.QtWidgets.QDateTimeEdit. dateChanged ( date )
参数

date QDate

PySide2.QtWidgets.QDateTimeEdit. dateTime ( )
返回类型

QDateTime

另请参阅

setDateTime()

PySide2.QtWidgets.QDateTimeEdit. dateTimeChanged ( dateTime )
参数

dateTime QDateTime

PySide2.QtWidgets.QDateTimeEdit. dateTimeFromText ( text )
参数

text – unicode

返回类型

QDateTime

返回适当日期时间为给定 text .

This virtual function is used by the datetime edit whenever it needs to interpret text entered by the user as a value.

另请参阅

textFromDateTime() validate()

PySide2.QtWidgets.QDateTimeEdit. displayFormat ( )
返回类型

unicode

PySide2.QtWidgets.QDateTimeEdit. displayedSections ( )
返回类型

Sections

PySide2.QtWidgets.QDateTimeEdit. maximumDate ( )
返回类型

QDate

另请参阅

setMaximumDate()

PySide2.QtWidgets.QDateTimeEdit. maximumDateTime ( )
返回类型

QDateTime

PySide2.QtWidgets.QDateTimeEdit. maximumTime ( )
返回类型

QTime

另请参阅

setMaximumTime()

PySide2.QtWidgets.QDateTimeEdit. minimumDate ( )
返回类型

QDate

另请参阅

setMinimumDate()

PySide2.QtWidgets.QDateTimeEdit. minimumDateTime ( )
返回类型

QDateTime

PySide2.QtWidgets.QDateTimeEdit. minimumTime ( )
返回类型

QTime

另请参阅

setMinimumTime()

PySide2.QtWidgets.QDateTimeEdit. sectionAt ( index )
参数

index int

返回类型

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 ( )
返回类型

int

PySide2.QtWidgets.QDateTimeEdit. sectionText ( section )
参数

section Section

返回类型

unicode

Returns the text from the given section .

另请参阅

currentSection()

PySide2.QtWidgets.QDateTimeEdit. setCalendar ( calendar )
参数

calendar QCalendar

PySide2.QtWidgets.QDateTimeEdit. setCalendarPopup ( enable )
参数

enable bool

另请参阅

calendarPopup()

PySide2.QtWidgets.QDateTimeEdit. setCalendarWidget ( calendarWidget )
参数

calendarWidget QCalendarWidget

设置给定 calendarWidget as the widget to be used for the calendar pop-up. The editor does not automatically take ownership of the calendar widget.

注意

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

PySide2.QtWidgets.QDateTimeEdit. setCurrentSection ( section )
参数

section Section

另请参阅

currentSection()

PySide2.QtWidgets.QDateTimeEdit. setCurrentSectionIndex ( index )
参数

index int

PySide2.QtWidgets.QDateTimeEdit. setDate ( date )
参数

date QDate

另请参阅

date()

PySide2.QtWidgets.QDateTimeEdit. setDateRange ( min , max )
参数
  • min QDate

  • max QDate

Set the range of allowed dates for the date time edit.

This convenience function sets the minimumDate and maximumDate 特性。

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 等于 min maximumTime property was less then the minimumTime property, the maximumTime property is set to the minimumTime property. Otherwise, this preserves the maximumTime 特性。

PySide2.QtWidgets.QDateTimeEdit. setDateTime ( dateTime )
参数

dateTime QDateTime

另请参阅

dateTime()

PySide2.QtWidgets.QDateTimeEdit. setDateTimeRange ( min , max )
参数
  • min QDateTime

  • max QDateTime

Set the range of allowed date-times for the date time edit.

This convenience function sets the minimumDateTime and maximumDateTime 特性。

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 .

PySide2.QtWidgets.QDateTimeEdit. setDisplayFormat ( format )
参数

format – unicode

另请参阅

displayFormat()

PySide2.QtWidgets.QDateTimeEdit. setMaximumDate ( max )
参数

max QDate

另请参阅

maximumDate()

PySide2.QtWidgets.QDateTimeEdit. setMaximumDateTime ( dt )
参数

dt QDateTime

另请参阅

maximumDateTime()

PySide2.QtWidgets.QDateTimeEdit. setMaximumTime ( max )
参数

max QTime

另请参阅

maximumTime()

PySide2.QtWidgets.QDateTimeEdit. setMinimumDate ( min )
参数

min QDate

另请参阅

minimumDate()

PySide2.QtWidgets.QDateTimeEdit. setMinimumDateTime ( dt )
参数

dt QDateTime

另请参阅

minimumDateTime()

PySide2.QtWidgets.QDateTimeEdit. setMinimumTime ( min )
参数

min QTime

另请参阅

minimumTime()

PySide2.QtWidgets.QDateTimeEdit. setSelectedSection ( section )
参数

section Section

Selects section 。若 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.

另请参阅

currentSection()

PySide2.QtWidgets.QDateTimeEdit. setTime ( time )
参数

time QTime

另请参阅

time()

PySide2.QtWidgets.QDateTimeEdit. setTimeRange ( min , max )
参数
  • min QTime

  • max QTime

Set the range of allowed times for the date time edit.

This convenience function sets the minimumTime and maximumTime 特性。

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 .

PySide2.QtWidgets.QDateTimeEdit. setTimeSpec ( spec )
参数

spec TimeSpec

另请参阅

timeSpec()

PySide2.QtWidgets.QDateTimeEdit. textFromDateTime ( dt )
参数

dt QDateTime

返回类型

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

另请参阅

dateTimeFromText() validate()

PySide2.QtWidgets.QDateTimeEdit. time ( )
返回类型

QTime

返回日期时间编辑的时间。

另请参阅

setTime()

PySide2.QtWidgets.QDateTimeEdit. timeChanged ( time )
参数

time QTime

PySide2.QtWidgets.QDateTimeEdit. timeSpec ( )
返回类型

TimeSpec

另请参阅

setTimeSpec()