QDateTimeEdit 类提供用于编辑日期和时间的 Widget。 更多...
头: | #include <QDateTimeEdit> |
qmake: | QT += widgets |
继承: | QAbstractSpinBox |
继承者: |
enum | Section { NoSection, AmPmSection, MSecSection, SecondSection, ..., YearSection } |
flags | Sections |
|
|
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 |
Sections | 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 |
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 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 ().
另请参阅 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
|
The Sections type is a typedef for QFlags <Section>. It stores an OR combination of Section values.
This property holds the current calendar pop-up show mode.
The calendar pop-up will be shown upon clicking the arrow button. This property is valid only if there is a valid date display format.
该特性在 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
This format is 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 ().
This property holds the currently displayed fields of the date time edit
Returns a bit set of the displayed sections for this format. setDisplayFormat() , displayFormat ()
访问函数:
Sections | displayedSections () const |
This property holds the maximum date of the date time edit
When setting this property the 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
When setting this property the 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
When setting this property the 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
When setting this property the 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
When setting this property the 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 |
此特性保持 QTime that is set in the widget
默认情况下,此特性包含时间 00:00:00 和 0 毫秒。
访问函数:
QTime | time () const |
void | setTime (const QTime & time ) |
通知程序信号:
void | timeChanged (const QTime & time ) |
This property holds the current timespec used by the date time edit.
该特性在 Qt 4.4 引入。
访问函数:
Qt::TimeSpec | timeSpec () const |
void | setTimeSpec (Qt::TimeSpec spec ) |
构造空的日期时间编辑器采用 parent .
构造空的日期时间编辑器采用 parent . The value is set to datetime .
构造空的日期时间编辑器采用 parent . The value is set to date .
构造空的日期时间编辑器采用 parent . The 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 ().
[override virtual]
void
QDateTimeEdit::
clear
()
重实现自 QAbstractSpinBox::clear ().
返回日期时间编辑的日期。
注意: Getter 函数对于特性 date .
另请参阅 setDate ().
[signal]
void
QDateTimeEdit::
dateChanged
(const
QDate
&
date
)
This signal is emitted whenever the date is changed. The new date is passed in date .
注意: 通知程序信号对于特性 date .
[signal]
void
QDateTimeEdit::
dateTimeChanged
(const
QDateTime
&
datetime
)
This signal is emitted whenever the date or time is changed. The new date and time is passed in datetime .
注意: 通知程序信号对于特性 dateTime .
[virtual protected]
QDateTime
QDateTimeEdit::
dateTimeFromText
(const
QString
&
text
) const
返回适当日期时间为给定 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 ().
[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 with the values from this QDataTimeEdit. This method is useful for subclasses when they need a 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 ().
Returns the Section at index .
If the format is 'yyyy/MM/dd', sectionAt(0) returns YearSection , sectionAt(1) returns MonthSection , and sectionAt(2) returns YearSection ,
该函数在 Qt 4.3 引入。
Returns the text from the given section .
另请参阅 currentSection ().
设置给定 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.
该函数在 Qt 4.4 引入。
另请参阅 calendarWidget () 和 calendarPopup .
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 ().
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 ().
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 ().
[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
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 ().
返回日期时间编辑的时间。
注意: Getter 函数对于特性 time .
另请参阅 setTime ().
[signal]
void
QDateTimeEdit::
timeChanged
(const
QTime
&
time
)
This signal is emitted whenever the time is changed. The new time is passed in 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 ().