The QDateTimeEdit class provides a widget for editing dates and times. 更多...
继承 QAbstractSpinBox .
Inherited by QDateEdit and QTimeEdit .
The QDateTimeEdit class provides a widget for editing dates and times.
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 ().
QDateTimeEdit *dateEdit = new 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 minimum value for QDateTimeEdit is 14 September 1752, and 2 January 4713BC for QDate . You can change this by calling setMinimumDate (), setMaximumDate (), setMinimumTime (), and setMaximumTime ().
QDateTimeEdit can be configured to allow a QCalendarWidget to be used to select dates. This is enabled by setting the calendarPopup 特性。 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 ().
|
A date time editing widget shown in the Windows XP widget style . |
|
A date time editing widget shown in the Macintosh widget style . |
|
A date time editing widget shown in the Plastique widget style . |
| 常量 | 值 |
|---|---|
| QDateTimeEdit.NoSection | 0x0000 |
| QDateTimeEdit.AmPmSection | 0x0001 |
| QDateTimeEdit.MSecSection | 0x0002 |
| QDateTimeEdit.SecondSection | 0x0004 |
| QDateTimeEdit.MinuteSection | 0x0008 |
| QDateTimeEdit.HourSection | 0x0010 |
| QDateTimeEdit.DaySection | 0x0100 |
| QDateTimeEdit.MonthSection | 0x0200 |
| QDateTimeEdit.YearSection | 0x0400 |
The Sections type is a typedef for QFlags <Section>. It stores an OR combination of Section values.
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs an empty date time editor with a parent .
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs an empty date time editor with a parent 。 value is set to datetime .
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs an empty date time editor with a parent 。 value is set to date .
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs an empty date time editor with a parent 。 value is set to time .
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.
该函数在 Qt 4.4 引入。
另请参阅 setCalendarWidget ().
重实现自 QAbstractSpinBox.clear ().
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.
另请参阅 textFromDateTime () 和 validate ().
重实现自 QObject.event ().
重实现自 QAbstractSpinBox.fixup ().
重实现自 QWidget.focusInEvent ().
重实现自 QWidget.focusNextPrevChild ().
初始化 option 采用值来自此 QDataTimeEdit. This method is useful for subclasses when they need a QStyleOptionSpinBox ,但 don't want to fill in all the information themselves.
另请参阅 QStyleOption.initFrom ().
重实现自 QWidget.keyPressEvent ().
重实现自 QWidget.mousePressEvent ().
重实现自 QWidget.paintEvent ().
Returns the Section at index .
If the format is 'yyyy/MM/dd', sectionAt(0) returns YearSection , sectionAt(1) 返回 MonthSection , and sectionAt(2) returns YearSection ,
该函数在 Qt 4.3 引入。
Returns the text from the given section .
另请参阅 currentSection ().
calendarWidget argument has it's ownership transferred to Qt.
设置给定 calendarWidget as the widget to be used for the calendar pop-up. The editor does not automatically take ownership of the calendar widget.
注意: calendarPopup 必须是 set to true before setting the calendar widget.
该函数在 Qt 4.4 引入。
另请参阅 calendarWidget () 和 calendarPopup .
This method is also a Qt slot with the C++ signature void setDate(const QDate&) .
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.
另请参阅 setMinimumDate (), maximumDate (), setMaximumDate (), clearMinimumDate (), setMinimumTime (), maximumTime (), setMaximumTime (), clearMinimumTime (),和 QDate.isValid ().
This method is also a Qt slot with the C++ signature void setDateTime(const QDateTime&) .
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.
该函数在 Qt 4.4 引入。
另请参阅 setMinimumDate (), maximumDate (), setMaximumDate (), clearMinimumDate (), setMinimumTime (), maximumTime (), setMaximumTime (), clearMinimumTime (),和 QDateTime.isValid ().
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.
该函数在 Qt 4.2 引入。
另请参阅 currentSection ().
This method is also a Qt slot with the C++ signature void setTime(const QTime&) .
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.
另请参阅 setMinimumDate (), maximumDate (), setMaximumDate (), clearMinimumDate (), setMinimumTime (), maximumTime (), setMaximumTime (), clearMinimumTime (),和 QTime.isValid ().
重实现自 QWidget.sizeHint ().
重实现自 QAbstractSpinBox.stepBy ().
重实现自 QAbstractSpinBox.stepEnabled ().
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 ().
重实现自 QAbstractSpinBox.validate ().
重实现自 QWidget.wheelEvent ().
This is the default overload of this signal.
This signal is emitted whenever the date is changed. The new date is passed in date .
This is the default overload of this signal.
This signal is emitted whenever the date or time is changed. The new date and time is passed in datetime .
This is the default overload of this signal.
This signal is emitted whenever the time is changed. The new time is passed in time .