The QDateTimeEdit 类提供用于编辑日期和时间的 Widget。 更多...
| 头: | #include <QDateTimeEdit> |
| 继承: | QAbstractSpinBox |
| 继承者: | QDateEdit and QTimeEdit |
| enum | Section { NoSection, AmPmSection, MSecSection, SecondSection, ..., YearSection } |
| flags | 章节 |
|
|
| QDateTimeEdit (QWidget * parent = 0) | |
| QDateTimeEdit (const QDateTime & datetime , QWidget * parent = 0) | |
| QDateTimeEdit (const QDate & date , QWidget * parent = 0) | |
| QDateTimeEdit (const QTime & time , QWidget * parent = 0) | |
| bool | calendarPopup () const |
| QCalendarWidget * | calendarWidget () const |
| void | clearMaximumDate () |
| void | clearMaximumDateTime () |
| void | clearMaximumTime () |
| void | clearMinimumDate () |
| void | clearMinimumDateTime () |
| void | clearMinimumTime () |
| Section | currentSection () const |
| int | currentSectionIndex () const |
| QDate | date () const |
| QDateTime | dateTime () const |
| QString | displayFormat () const |
| 章节 | displayedSections () const |
| QDate | maximumDate () const |
| QDateTime | maximumDateTime () const |
| QTime | maximumTime () const |
| QDate | minimumDate () const |
| QDateTime | minimumDateTime () const |
| QTime | minimumTime () const |
| Section | sectionAt (int index ) const |
| int | sectionCount () const |
| QString | sectionText (Section section ) const |
| void | setCalendarPopup (bool enable ) |
| void | setCalendarWidget (QCalendarWidget * calendarWidget ) |
| void | setCurrentSection (Section section ) |
| void | setCurrentSectionIndex (int index ) |
| void | setDateRange (const QDate & min , const QDate & max ) |
| void | setDateTimeRange (const QDateTime & min , const QDateTime & max ) |
| void | setDisplayFormat (const QString & format ) |
| void | setMaximumDate (const QDate & max ) |
| void | setMaximumDateTime (const QDateTime & dt ) |
| void | setMaximumTime (const QTime & max ) |
| void | setMinimumDate (const QDate & min ) |
| void | setMinimumDateTime (const QDateTime & dt ) |
| void | setMinimumTime (const QTime & min ) |
| void | setSelectedSection (Section section ) |
| void | setTimeRange (const QTime & min , const QTime & max ) |
| void | setTimeSpec (Qt::TimeSpec spec ) |
| QTime | time () const |
| Qt::TimeSpec | timeSpec () const |
| virtual void | clear () |
| virtual bool | event (QEvent * event ) |
| virtual QSize | sizeHint () const |
| virtual void | stepBy (int steps ) |
| void | setDate (const QDate & date ) |
| void | setDateTime (const QDateTime & dateTime ) |
| void | setTime (const QTime & time ) |
| void | dateChanged (const QDate & date ) |
| void | dateTimeChanged (const QDateTime & datetime ) |
| void | timeChanged (const QTime & time ) |
| virtual QDateTime | dateTimeFromText (const QString & text ) const |
| void | initStyleOption (QStyleOptionSpinBox * option ) const |
| virtual QString | textFromDateTime (const QDateTime & dateTime ) const |
| virtual void | fixup (QString & input ) const |
| virtual void | focusInEvent (QFocusEvent * event ) |
| virtual bool | focusNextPrevChild (bool next ) |
| virtual void | keyPressEvent (QKeyEvent * event ) |
| virtual void | mousePressEvent (QMouseEvent * event ) |
| virtual void | paintEvent (QPaintEvent * event ) |
| virtual StepEnabled | stepEnabled () const |
| virtual QValidator::State | validate (QString & text , int & pos ) const |
| virtual void | wheelEvent (QWheelEvent * event ) |
The QDateTimeEdit 类提供用于编辑日期和时间的 Widget。
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 (),和 setMaximumTime ().
QDateTimeEdit can be configured to allow a QCalendarWidget 用于选择日期。这的启用是通过设置 calendarPopup 特性。此外,可以提供自定义日历 Widget 为用作日历弹出通过调用 setCalendarWidget () 函数。可以检索现有日历 Widget 采用 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 . |
另请参阅 QDateEdit , QTimeEdit , QDate ,和 QTime .
| 常量 | 值 |
|---|---|
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
|
Sections 类型是 typedef 对于 QFlags <Section>。它存储 Section 值的 OR 组合。
This property holds the current calendar pop-up showing mode.
日历弹出将展示,当点击箭头按钮时。此特性才有效,若存在有效日期显示格式。
该特性在 Qt 4.2 引入。
访问函数:
| bool | calendarPopup () const |
| void | setCalendarPopup (bool enable ) |
另请参阅 setDisplayFormat ().
This property holds the current section of the spinbox setCurrentSection().
访问函数:
| Section | currentSection () const |
| void | setCurrentSection (Section section ) |
此特性保持自旋框的当前区间索引。
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 etc.
setCurrentSection()
该特性在 Qt 4.3 引入。
访问函数:
| int | currentSectionIndex () const |
| void | setCurrentSectionIndex (int index ) |
另请参阅 currentSection ().
This property holds the QDate that is set in the widget.
By default, this property contains a date that refers to January 1, 2000.
访问函数:
| QDate | date () const |
| void | setDate (const QDate & date ) |
通知程序信号:
| void | dateChanged (const QDate & date ) |
This property holds the QDateTime that is set in the QDateTimeEdit.
When setting this property the timespec of the QDateTimeEdit remains the same and the timespec of the new QDateTime 被忽略。
By default, this property contains a date that refers to January 1, 2000 and a time of 00:00:00 and 0 milliseconds.
访问函数:
| QDateTime | dateTime () const |
| void | setDateTime (const QDateTime & dateTime ) |
通知程序信号:
| void | dateTimeChanged (const QDateTime & datetime ) |
This property holds the format used to display the time/date of the date time edit.
This format is the same as the one used described in QDateTime::toString () 和 QDateTime::fromString ()
Example format strings (assuming that the date is 2nd of July 1969):
| 格式 | 结果 |
|---|---|
| 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 21 (2000-2099).
If you specify an invalid format the format will not be set.
访问函数:
| QString | displayFormat () const |
| void | setDisplayFormat (const QString & format ) |
另请参阅 QDateTime::toString () 和 displayedSections ().
此特性保持日期时间编辑的目前显示字段。
返回此格式显示区间的位集。 setDisplayFormat() , displayFormat ()
访问函数:
| 章节 | displayedSections () const |
此特性保持日期时间编辑的最大日期。
当设置此特性 minimumDate is adjusted if necessary to ensure that the range remains valid. If the date is not a valid QDate object, this function does nothing.
By default, this property contains a date that refers to December 31, 7999.
访问函数:
| QDate | maximumDate () const |
| void | setMaximumDate (const QDate & max ) |
| void | clearMaximumDate () |
另请参阅 minimumDate , minimumTime , maximumTime ,和 setDateRange ().
此特性保持日期时间编辑的最大日期时间。
当设置此特性 minimumDateTime () is adjusted if necessary to ensure that the range remains valid. If the datetime is not a valid QDateTime object, this function does nothing.
The default maximumDateTime can be restored with clearMaximumDateTime().
By default, this property contains a date that refers to 31 December, 7999 and a time of 23:59:59 and 999 milliseconds.
该特性在 Qt 4.4 引入。
访问函数:
| QDateTime | maximumDateTime () const |
| void | setMaximumDateTime (const QDateTime & dt ) |
| void | clearMaximumDateTime () |
另请参阅 minimumDateTime (), minimumTime (), maximumTime (), minimumDate (), maximumDate (), setDateTimeRange (), setDateRange (), setTimeRange (), clearMinimumDateTime (), clearMinimumDate (), clearMaximumDate (), clearMinimumTime (),和 clearMaximumTime ().
此特性保持日期时间编辑的最大时间。
当设置此特性时, minimumTime is adjusted if necessary to ensure that the range remains valid. If the time is not a valid QTime object, this function does nothing.
By default, this property contains a time of 23:59:59 and 999 milliseconds.
访问函数:
| QTime | maximumTime () const |
| void | setMaximumTime (const QTime & max ) |
| void | clearMaximumTime () |
另请参阅 minimumTime , minimumDate , maximumDate ,和 setTimeRange ().
此特性保持日期时间编辑的最小日期。
当设置此特性 maximumDate is adjusted if necessary, to ensure that the range remains valid. If the date is not a valid QDate object, this function does nothing.
By default, this property contains a date that refers to September 14, 1752. The minimum date must be at least the first day in year 100, otherwise setMinimumDate() has no effect.
访问函数:
| QDate | minimumDate () const |
| void | setMinimumDate (const QDate & min ) |
| void | clearMinimumDate () |
另请参阅 minimumTime (), maximumTime (),和 setDateRange ().
此特性保持日期时间编辑的最小日期时间。
当设置此特性 maximumDateTime () is adjusted if necessary to ensure that the range remains valid. If the datetime is not a valid QDateTime object, this function does nothing.
The default minimumDateTime can be restored with clearMinimumDateTime()
By default, this property contains a date that refers to September 14, 1752 and a time of 00:00:00 and 0 milliseconds.
该特性在 Qt 4.4 引入。
访问函数:
| QDateTime | minimumDateTime () const |
| void | setMinimumDateTime (const QDateTime & dt ) |
| void | clearMinimumDateTime () |
另请参阅 maximumDateTime (), minimumTime (), maximumTime (), minimumDate (), maximumDate (), setDateTimeRange (), setDateRange (), setTimeRange (), clearMaximumDateTime (), clearMinimumDate (), clearMaximumDate (), clearMinimumTime (),和 clearMaximumTime ().
此特性保持日期时间编辑的最小时间。
当设置此特性 maximumTime is adjusted if necessary, to ensure that the range remains valid. If the time is not a valid QTime object, this function does nothing.
默认情况下,此特性包含时间 00:00:00 和 0 毫秒。
访问函数:
| QTime | minimumTime () const |
| void | setMinimumTime (const QTime & min ) |
| void | clearMinimumTime () |
另请参阅 maximumTime , minimumDate , maximumDate ,和 setTimeRange ().
This property holds the number of sections displayed. If the format is 'yyyy/yy/yyyy', sectionCount returns 3.
该特性在 Qt 4.3 引入。
访问函数:
| int | sectionCount () const |
This property holds the QTime that is set in the widget.
默认情况下,此特性包含时间 00:00:00 和 0 毫秒。
访问函数:
| QTime | time () const |
| void | setTime (const QTime & time ) |
通知程序信号:
| void | timeChanged (const QTime & time ) |
此特性保持用于日期时间编辑的当前时间规范。
该特性在 Qt 4.4 引入。
访问函数:
| Qt::TimeSpec | timeSpec () const |
| void | setTimeSpec (Qt::TimeSpec spec ) |
构造空的日期时间编辑器采用 parent .
构造空的日期时间编辑器采用 parent 。值被设为 datetime .
构造空的日期时间编辑器采用 parent 。值被设为 date .
构造空的日期时间编辑器采用 parent 。值被设为 time .
返回用于编辑器的日历 Widget 若 calendarPopup 被设为 true 且 (sections() & DateSections_Mask ) != 0.
此函数创建并返回日历 Widget 若没有设置。
该函数在 Qt 4.4 引入。
另请参阅 setCalendarWidget ().
[虚拟]
void
QDateTimeEdit::
clear
()
重实现自 QAbstractSpinBox::clear ().
[virtual protected]
QDateTime
QDateTimeEdit::
dateTimeFromText
(const
QString
&
text
) const
返回适当日期时间为给定 text .
此虚函数可以用于日期时间编辑,每当它需要将用户键入文本解释为值时。
另请参阅 textFromDateTime () 和 validate ().
[虚拟]
bool
QDateTimeEdit::
event
(
QEvent
*
event
)
重实现自 QObject::event ().
[virtual protected]
void
QDateTimeEdit::
fixup
(
QString
&
input
) const
重实现自 QAbstractSpinBox::fixup ().
[virtual protected]
void
QDateTimeEdit::
focusInEvent
(
QFocusEvent
*
event
)
重实现自 QWidget::focusInEvent ().
[virtual protected]
bool
QDateTimeEdit::
focusNextPrevChild
(
bool
next
)
重实现自 QWidget::focusNextPrevChild ().
[protected]
void
QDateTimeEdit::
initStyleOption
(
QStyleOptionSpinBox
*
option
) const
初始化 option 采用来自此 QDataTimeEdit 的值。此方法对于子类很有用,当它们需要 QStyleOptionSpinBox ,但不希望自己填充所有信息。
另请参阅 QStyleOption::initFrom ().
[virtual protected]
void
QDateTimeEdit::
keyPressEvent
(
QKeyEvent
*
event
)
重实现自 QWidget::keyPressEvent ().
[virtual protected]
void
QDateTimeEdit::
mousePressEvent
(
QMouseEvent
*
event
)
重实现自 QWidget::mousePressEvent ().
[virtual protected]
void
QDateTimeEdit::
paintEvent
(
QPaintEvent
*
event
)
重实现自 QWidget::paintEvent ().
返回区间按 index .
若格式为 yyyy/MM/dd,sectionAt(0) 返回 YearSection ,sectionAt(1) 返回 MonthSection ,和 sectionAt(2) 返回 YearSection ,
该函数在 Qt 4.3 引入。
返回文本从给定 section .
另请参阅 currentSection ().
设置给定 calendarWidget 作为用于日历弹出的 Widget。编辑器不会自动拥有日历 Widget 的所有权。
注意: calendarPopup 必须被设为 true 在设置日历 Widget 前。
该函数在 Qt 4.4 引入。
另请参阅 calendarWidget () 和 calendarPopup .
Convenience function to set minimum and maximum date with one function call.
setDateRange(min, max);
类似于:
setMinimumDate(min); setMaximumDate(max);
若 min or max are not valid, this function does nothing.
另请参阅 setMinimumDate (), maximumDate (), setMaximumDate (), clearMinimumDate (), setMinimumTime (), maximumTime (), setMaximumTime (), clearMinimumTime (),和 QDate::isValid ().
Convenience function to set minimum and maximum date time with one function call.
setDateTimeRange(min, max);
类似于:
setMinimumDateTime(min); setMaximumDateTime(max);
若 min or max are not valid, this function does nothing.
该函数在 Qt 4.4 引入。
另请参阅 setMinimumDate (), maximumDate (), setMaximumDate (), clearMinimumDate (), setMinimumTime (), maximumTime (), setMaximumTime (), clearMinimumTime (),和 QDateTime::isValid ().
选择 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 ().
Convenience function to set minimum and maximum time with one function call.
setTimeRange(min, max);
类似于:
setMinimumTime(min); setMaximumTime(max);
若 min or max are not valid, this function does nothing.
另请参阅 setMinimumDate (), maximumDate (), setMaximumDate (), clearMinimumDate (), setMinimumTime (), maximumTime (), setMaximumTime (), clearMinimumTime (),和 QTime::isValid ().
[虚拟]
QSize
QDateTimeEdit::
sizeHint
() const
重实现自 QWidget::sizeHint ().
[虚拟]
void
QDateTimeEdit::
stepBy
(
int
steps
)
重实现自 QAbstractSpinBox::stepBy ().
[virtual protected]
StepEnabled
QDateTimeEdit::
stepEnabled
() const
重实现自 QAbstractSpinBox::stepEnabled ().
[virtual protected]
QString
QDateTimeEdit::
textFromDateTime
(const
QDateTime
&
dateTime
) const
此虚函数用于日期时间编辑,每当它需要显示 dateTime .
若重实现这,还可能需要重实现 validate ().
另请参阅 dateTimeFromText () 和 validate ().
[virtual protected]
QValidator::State
QDateTimeEdit::
validate
(
QString
&
text
,
int
&
pos
) const
重实现自 QAbstractSpinBox::validate ().
[virtual protected]
void
QDateTimeEdit::
wheelEvent
(
QWheelEvent
*
event
)
重实现自 QWidget::wheelEvent ().