Q3DateEdit Class

The Q3DateEdit class provides a date editor. 更多...

头: #include <Q3DateEdit>
继承: Q3DateTimeEditBase

公共类型

enum Order { MDY, DMY, YMD }

特性

公共函数

Q3DateEdit (QWidget * parent = 0, const char * name = 0)
Q3DateEdit (const QDate & date , QWidget * parent = 0, const char * name = 0)
~Q3DateEdit ()
bool autoAdvance () const
QDate date () const
QDate maxValue () const
QDate minValue () const
Order order () const
QString separator () const
virtual void setAutoAdvance (bool advance )
virtual void setMaxValue (const QDate & d )
virtual void setMinValue (const QDate & d )
virtual void setOrder (Order order )
virtual void setRange (const QDate & min , const QDate & max )
virtual void setSeparator (const QString & s )

重实现公共函数

virtual QSize minimumSizeHint () const
virtual QSize sizeHint () const

公共槽

virtual void setDate (const QDate & date )

信号

void valueChanged (const QDate & date )

保护函数

virtual void fix ()
virtual void setDay (int day )
virtual void setMonth (int month )
virtual void setYear (int year )

重实现保护函数

virtual bool event (QEvent * e )
virtual void resizeEvent (QResizeEvent *)
virtual QString sectionFormattedText (int sec )
virtual void timerEvent (QTimerEvent *)

保护槽

void updateButtons ()

额外继承成员

详细描述

The Q3DateEdit class provides a date editor.

Q3DateEdit allows the user to edit dates by using the keyboard or the arrow keys to increase/decrease date values. The arrow keys can be used to move from section to section within the Q3DateEdit box. Dates appear in accordance with the local date/time settings or in year, month, day order if the system doesn't provide this information. It is recommended that the Q3DateEdit be initialised with a date, e.g.

Q3DateEdit *dateEdit = new Q3DateEdit(QDate::currentDate(), this);
dateEdit->setRange(QDate::currentDate().addDays(-365),
                    QDate::currentDate().addDays( 365));
dateEdit->setOrder(Q3DateEdit::MDY);
dateEdit->setAutoAdvance(true);
					

Here we've created a new Q3DateEdit object initialised 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. If the auto advance property is true (as we've set it here) when the user completes a section of the date, e.g. enters two digits for the month, they are automatically taken to the next section.

The maximum and minimum values for a date value in the date editor default to the maximum and minimum values for a QDate . You can change this by calling setMinValue (), setMaxValue () 或 setRange ().

Terminology: A Q3DateEdit widget comprises three 'sections', one each for the year, month and day. You can change the separator character using Q3DateTimeEditor::setSeparator(), by default the separator will be taken from the systems settings. If that is not possible, it defaults to "-".

Date Time Widgets

另请参阅 QDate , Q3TimeEdit ,和 Q3DateTimeEdit .

成员类型文档编制

enum Q3DateEdit:: Order

This enum defines the order in which the sections that comprise a date appear.

常量 描述
Q3DateEdit::MDY 1 month-day-year
Q3DateEdit::DMY 0 day-month-year
Q3DateEdit::YMD 2 year-month-day (the default)

特性文档编制

autoAdvance : bool

This property holds whether the editor automatically advances to the next section.

If autoAdvance is true, the editor will automatically advance focus to the next date section if a user has completed a section. The default is false.

访问函数:

bool autoAdvance () const
virtual void setAutoAdvance (bool advance )

date : QDate

This property holds the editor's date value.

If the date property is not valid, the editor displays all zeroes and Q3DateEdit::date() will return an invalid date. It is strongly recommended that the editor is given a default date value (e.g. currentDate()). That way, attempts to set the date property to an invalid date will fail.

When changing the date property, if the date is less than minValue (), or is greater than maxValue (), nothing happens.

访问函数:

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

maxValue : QDate

This property holds the editor's maximum value.

Setting the maximum date value for the editor is equivalent to calling Q3DateEdit::setRange ( minValue (), d ), where d is the maximum date. The default maximum date is 8000-12-31.

访问函数:

QDate maxValue () const
virtual void setMaxValue (const QDate & d )

另请参阅 minValue and setRange ().

minValue : QDate

This property holds the editor's minimum value.

Setting the minimum date value is equivalent to calling Q3DateEdit::setRange ( d , maxValue ()), where d is the minimum date. The default minimum date is 1752-09-14.

访问函数:

QDate minValue () const
virtual void setMinValue (const QDate & d )

另请参阅 maxValue and setRange ().

order : Order

This property holds the order in which the year, month and day appear.

The default order is locale dependent.

访问函数:

Order order () const
virtual void setOrder (Order order )

另请参阅 Order .

成员函数文档编制

Q3DateEdit:: Q3DateEdit ( QWidget * parent = 0, const char * name = 0)

Constructs an empty date editor which is a child of parent and called name name .

Q3DateEdit:: Q3DateEdit (const QDate & date , QWidget * parent = 0, const char * name = 0)

这是重载函数。

Constructs a date editor with the initial value date , parent parent and called name .

The date editor is initialized with date .

Q3DateEdit:: ~Q3DateEdit ()

销毁对象并释放任何分配资源。

[virtual protected] bool Q3DateEdit:: event ( QEvent * e )

重实现自 QObject::event ().

[virtual protected] void Q3DateEdit:: fix ()

Attempts to fix any invalid date entries.

The rules applied are as follows:

  • If the year has four digits it is left unchanged.
  • If the year has two digits, the year will be changed to four digits in the range current year - 70 to current year + 29.
  • If the year has three digits in the range 100..999, the current millennium, i.e. 2000, will be added giving a year in the range 2100..2999.
  • If the day or month is 0 then it will be set to 1 or the minimum valid day/month in the range.

[虚拟] QSize Q3DateEdit:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

[virtual protected] void Q3DateEdit:: resizeEvent ( QResizeEvent *)

重实现自 QWidget::resizeEvent ().

[virtual protected] QString Q3DateEdit:: sectionFormattedText ( int sec )

Returns the formatted number for section sec . This will correspond to either the year, month or day section, depending on the current display order.

另请参阅 setOrder ().

QString Q3DateEdit:: separator () const

Returns the editor's separator.

另请参阅 setSeparator ().

[virtual protected] void Q3DateEdit:: setDay ( int day )

Sets the day to day , which must be a valid day. The function will ensure that the day set is valid for the month and year.

[virtual protected] void Q3DateEdit:: setMonth ( int month )

Sets the month to month , which must be a valid month, i.e. between 1 and 12.

[虚拟] void Q3DateEdit:: setRange (const QDate & min , const QDate & max )

Sets the valid input range for the editor to be from min to max inclusive. If min is invalid no minimum date will be set. Similarly, if max is invalid no maximum date will be set.

[虚拟] void Q3DateEdit:: setSeparator (const QString & s )

Sets the separator to s . Note that currently only the first character of s 被使用。

另请参阅 separator ().

[virtual protected] void Q3DateEdit:: setYear ( int year )

Sets the year to year , which must be a valid year. The range currently supported is from 1752 to 8000.

另请参阅 QDate .

[虚拟] QSize Q3DateEdit:: sizeHint () const

重实现自 QWidget::sizeHint ().

[virtual protected] void Q3DateEdit:: timerEvent ( QTimerEvent *)

重实现自 QObject::timerEvent ().

[protected slot] void Q3DateEdit:: updateButtons ()

Enables/disables the push buttons according to the min/max date for this widget.

[signal] void Q3DateEdit:: valueChanged (const QDate & date )

This signal is emitted whenever the editor's value changes. The date parameter is the new value.