The QDateTimeEdit 類提供用於編輯日期和時間的 Widget。 更多...
| 頭: | #include <QDateTimeEdit> |
| 繼承: | QAbstractSpinBox |
| 繼承者: | QDateEdit and QTimeEdit |
| enum | Section { NoSection, AmPmSection, MSecSection, SecondSection, ..., YearSection } |
| flags | Sections |
|
|
| 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.
默認情況下,此特性包含指嚮 2000 年 1 月 1 日的日期。
訪問函數:
| 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).
若指定格式無效,格式將不設置。
訪問函數:
| 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 ().