The QDateTimeEdit 类提供用于编辑日期和时间的 Widget。 更多...
头: | #include <QDateTimeEdit> |
qmake: | QT += widgets |
继承: | QAbstractSpinBox |
继承者: | QDateEdit and QTimeEdit |
enum | Section { NoSection, AmPmSection, MSecSection, SecondSection, ..., YearSection } |
flags | 章节 |
|
|
QDateTimeEdit (QWidget * parent = Q_NULLPTR) | |
QDateTimeEdit (const QDateTime & datetime , QWidget * parent = Q_NULLPTR) | |
QDateTimeEdit (const QDate & date , QWidget * parent = Q_NULLPTR) | |
QDateTimeEdit (const QTime & time , QWidget * parent = Q_NULLPTR) | |
~QDateTimeEdit () | |
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 () override |
virtual bool | event (QEvent * event ) override |
virtual QSize | sizeHint () const override |
virtual void | stepBy (int steps ) override |
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 override |
virtual void | focusInEvent (QFocusEvent * event ) override |
virtual bool | focusNextPrevChild (bool next ) override |
virtual void | keyPressEvent (QKeyEvent * event ) override |
virtual void | mousePressEvent (QMouseEvent * event ) override |
virtual void | paintEvent (QPaintEvent * event ) override |
virtual StepEnabled | stepEnabled () const override |
virtual QValidator::State | validate (QString & text , int & pos ) const override |
virtual void | wheelEvent (QWheelEvent * event ) override |
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. You can change this by calling setMinimumDate (), taking into account that the minimum value for QDate is 2 January 4713BC.
Other useful functions are setMaximumDate (), setMinimumTime () 和 setMaximumTime ().
QDateTimeEdit can be configured to allow a QCalendarWidget 用于选择日期。这的启用是通过设置 calendarPopup 特性。此外,可以提供自定义日历 Widget 为用作日历弹出通过调用 setCalendarWidget () 函数。可以检索现有日历 Widget 采用 calendarWidget ().
另请参阅 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 组合。
此特性保持当前日历弹出显示模式。
日历弹出将展示,当点击箭头按钮时。此特性才有效,若存在有效日期显示格式。
该特性在 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 ) |
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.
setCurrentSection()
该特性在 Qt 4.3 引入。
访问函数:
int | currentSectionIndex () const |
void | setCurrentSectionIndex (int index ) |
另请参阅 currentSection ().
此特性保持 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 ) |
此特性保持 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
此格式的描述在 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 ().
This property holds the currently displayed fields of the date time edit
返回此格式显示区间的位集。 setDisplayFormat() , displayFormat ()
访问函数:
章节 | displayedSections () const |
This property holds the maximum date of the date time edit
当设置此特性 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 ().
This property holds the maximum datetime of the date time edit
当设置此特性 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 ().
This property holds the maximum time of the date time edit
当设置此特性时, 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 ().
This property holds the minimum date of the date time edit
当设置此特性 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 ().
This property holds the minimum datetime of the date time edit
当设置此特性 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 ().
This property holds the minimum time of the date time edit
当设置此特性 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 ().
此特性保持显示的区间数。若格式为 yyyy/yy/yyyy,sectionCount 返回 3
该特性在 Qt 4.3 引入。
访问函数:
int | sectionCount () const |
此特性保持 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 is set to true and ( sections () & DateSections_Mask ) != 0.
此函数创建并返回日历 Widget 若没有设置。
该函数在 Qt 4.4 引入。
另请参阅 setCalendarWidget ().
[override virtual]
void
QDateTimeEdit::
clear
()
重实现自 QAbstractSpinBox::clear ().
返回日期时间编辑的日期。
注意: Getter 函数对于特性 date .
另请参阅 setDate ().
[signal]
void
QDateTimeEdit::
dateChanged
(const
QDate
&
date
)
此信号被发射,每当日期改变时。新日期被传入 date .
注意: 通知程序信号对于特性 date .
[signal]
void
QDateTimeEdit::
dateTimeChanged
(const
QDateTime
&
datetime
)
此信号被发射,每当日期 (或时间) 改变时。新日期和时间被传入 datetime .
注意: 通知程序信号对于特性 dateTime .
[virtual protected]
QDateTime
QDateTimeEdit::
dateTimeFromText
(const
QString
&
text
) const
返回适当日期时间为给定 text .
此虚函数可以用于日期时间编辑,每当它需要将用户键入文本解释为值时。
另请参阅 textFromDateTime () 和 validate ().
[override virtual]
bool
QDateTimeEdit::
event
(
QEvent
*
event
)
重实现自 QObject::event ().
[override virtual protected]
void
QDateTimeEdit::
fixup
(
QString
&
input
) const
重实现自 QAbstractSpinBox::fixup ().
[override virtual protected]
void
QDateTimeEdit::
focusInEvent
(
QFocusEvent
*
event
)
重实现自 QWidget::focusInEvent ().
[override virtual protected]
bool
QDateTimeEdit::
focusNextPrevChild
(
bool
next
)
重实现自 QWidget::focusNextPrevChild ().
[protected]
void
QDateTimeEdit::
initStyleOption
(
QStyleOptionSpinBox
*
option
) const
初始化 option 采用来自此 QDataTimeEdit 的值。此方法对于子类很有用,当它们需要 QStyleOptionSpinBox ,但不希望自己填充所有信息。
另请参阅 QStyleOption::initFrom ().
[override virtual protected]
void
QDateTimeEdit::
keyPressEvent
(
QKeyEvent
*
event
)
重实现自 QWidget::keyPressEvent ().
[override virtual protected]
void
QDateTimeEdit::
mousePressEvent
(
QMouseEvent
*
event
)
重实现自 QWidget::mousePressEvent ().
[override 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 未存在于目前显示部分中,此函数什么都不做。若 section is NoSection ,此函数将取消选择编辑器中的所有文本。否则,此函数将光标和当前区间移动到选中区间。
该函数在 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 ().
[override virtual]
QSize
QDateTimeEdit::
sizeHint
() const
重实现自 QWidget::sizeHint ().
[override virtual]
void
QDateTimeEdit::
stepBy
(
int
steps
)
重实现自 QAbstractSpinBox::stepBy ().
[override virtual protected]
StepEnabled
QDateTimeEdit::
stepEnabled
() const
重实现自 QAbstractSpinBox::stepEnabled ().
[virtual protected]
QString
QDateTimeEdit::
textFromDateTime
(const
QDateTime
&
dateTime
) const
此虚函数用于日期时间编辑,每当它需要显示 dateTime .
若重实现这,还可能需要重实现 validate ().
另请参阅 dateTimeFromText () 和 validate ().
返回日期时间编辑的时间。
注意: Getter 函数对于特性 time .
另请参阅 setTime ().
[signal]
void
QDateTimeEdit::
timeChanged
(const
QTime
&
time
)
此信号被发射,每当时间改变时。新时间被传入 time .
注意: 通知程序信号对于特性 time .
[override virtual protected]
QValidator::State
QDateTimeEdit::
validate
(
QString
&
text
,
int
&
pos
) const
重实现自 QAbstractSpinBox::validate ().
[override virtual protected]
void
QDateTimeEdit::
wheelEvent
(
QWheelEvent
*
event
)
重实现自 QWidget::wheelEvent ().