QDateTimeEdit 類

The QDateTimeEdit 類提供用於編輯日期和時間的 Widget。 更多...

頭: #include <QDateTimeEdit>
qmake: QT += widgets
繼承: QAbstractSpinBox
繼承者: QDateEdit and QTimeEdit

公共類型

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
章節 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 ().

使用彈齣日曆 Widget

QDateTimeEdit can be configured to allow a QCalendarWidget 用於選擇日期。這的啓用是通過設置 calendarPopup 特性。此外,可以提供自定義日曆 Widget 為用作日曆彈齣通過調用 setCalendarWidget () 函數。可以檢索現有日曆 Widget 采用 calendarWidget ().

另請參閱 QDateEdit , QTimeEdit , QDate ,和 QTime .

成員類型文檔編製

enum QDateTimeEdit:: Section
flags QDateTimeEdit:: Sections

常量
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 (或) 組閤。

特性文檔編製

calendarPopup : bool

此特性保持當前日曆彈齣顯示模式。

日曆彈齣將展示,當點擊箭頭按鈕時。此特性纔有效,若存在有效日期顯示格式。

該特性在 Qt 4.2 引入。

訪問函數:

bool calendarPopup () const
void setCalendarPopup (bool enable )

另請參閱 setDisplayFormat ().

currentSection : Section

This property holds the current section of the spinbox setCurrentSection()

訪問函數:

Section currentSection () const
void setCurrentSection (Section section )

currentSectionIndex : int

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 ().

date : QDate

此特性保持 QDate that is set in the widget

默認情況下,此特性包含指嚮 2000 年 1 月 1 日的日期。

訪問函數:

QDate date () const
void setDate (const QDate & date )

通知程序信號:

void dateChanged (const QDate & date )

另請參閱 time and dateTime .

dateTime : QDateTime

此特性保持 QDateTime 的設置在 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 )

另請參閱 date and time .

displayFormat : QString

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).

若指定格式無效,格式將不設置。

訪問函數:

QString displayFormat () const
void setDisplayFormat (const QString & format )

另請參閱 QDateTime::toString () 和 displayedSections ().

displayedSections : const Sections

This property holds the currently displayed fields of the date time edit

返迴此格式顯示區間的位集。 setDisplayFormat() , displayFormat ()

訪問函數:

章節 displayedSections () const

maximumDate : QDate

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 ().

maximumDateTime : QDateTime

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 ().

maximumTime : QTime

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 ().

minimumDate : QDate

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 ().

minimumDateTime : QDateTime

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 ().

minimumTime : QTime

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 ().

sectionCount : const int

此特性保持顯示的區間數。若格式為 yyyy/yy/yyyy,sectionCount 返迴 3

該特性在 Qt 4.3 引入。

訪問函數:

int sectionCount () const

time : QTime

此特性保持 QTime that is set in the widget

默認情況下,此特性包含時間 00:00:00 和 0 毫秒。

訪問函數:

QTime time () const
void setTime (const QTime & time )

通知程序信號:

void timeChanged (const QTime & time )

另請參閱 date and dateTime .

timeSpec : Qt::TimeSpec

此特性保持用於日期時間編輯的當前時間規範。

該特性在 Qt 4.4 引入。

訪問函數:

Qt::TimeSpec timeSpec () const
void setTimeSpec (Qt::TimeSpec spec )

成員函數文檔編製

QDateTimeEdit:: QDateTimeEdit ( QWidget * parent = Q_NULLPTR)

構造空的日期時間編輯器采用 parent .

QDateTimeEdit:: QDateTimeEdit (const QDateTime & datetime , QWidget * parent = Q_NULLPTR)

構造空的日期時間編輯器采用 parent 。值被設為 datetime .

QDateTimeEdit:: QDateTimeEdit (const QDate & date , QWidget * parent = Q_NULLPTR)

構造空的日期時間編輯器采用 parent 。值被設為 date .

QDateTimeEdit:: QDateTimeEdit (const QTime & time , QWidget * parent = Q_NULLPTR)

構造空的日期時間編輯器采用 parent 。值被設為 time .

QDateTimeEdit:: ~QDateTimeEdit ()

析構函數。

QCalendarWidget *QDateTimeEdit:: calendarWidget () const

返迴用於編輯器的日曆 Widget 若 calendarPopup is set to true and ( sections () & DateSections_Mask ) != 0.

此函數創建並返迴日曆 Widget 若沒有設置。

該函數在 Qt 4.4 引入。

另請參閱 setCalendarWidget ().

[override virtual] void QDateTimeEdit:: clear ()

重實現自 QAbstractSpinBox::clear ().

QDate QDateTimeEdit:: date () const

返迴日期時間編輯的日期。

注意: 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 ().

Section QDateTimeEdit:: sectionAt ( int index ) const

返迴區間按 index .

若格式為 yyyy/MM/dd,sectionAt(0) 返迴 YearSection ,sectionAt(1) 返迴 MonthSection ,和 sectionAt(2) 返迴 YearSection ,

該函數在 Qt 4.3 引入。

QString QDateTimeEdit:: sectionText ( Section section ) const

返迴文本從給定 section .

另請參閱 currentSection ().

void QDateTimeEdit:: setCalendarWidget ( QCalendarWidget * calendarWidget )

設置給定 calendarWidget 作為用於日曆彈齣的 Widget。編輯器不會自動擁有日曆 Widget 的所有權。

注意: calendarPopup 必須被設為 true 在設置日曆 Widget 前。

該函數在 Qt 4.4 引入。

另請參閱 calendarWidget () 和 calendarPopup .

void QDateTimeEdit:: setDateRange (const QDate & min , const QDate & max )

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 ().

void QDateTimeEdit:: setDateTimeRange (const QDateTime & min , const QDateTime & max )

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 ().

void QDateTimeEdit:: setSelectedSection ( Section section )

選擇 section 。若 section 未存在於目前顯示部分中,此函數什麼都不做。若 section is NoSection ,此函數將取消選擇編輯器中的所有文本。否則,此函數將光標和當前區間移動到選中區間。

該函數在 Qt 4.2 引入。

另請參閱 currentSection ().

void QDateTimeEdit:: setTimeRange (const QTime & min , const QTime & max )

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 ().

QTime QDateTimeEdit:: time () const

返迴日期時間編輯的時間。

注意: 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 ().