返回介绍

QDateEdit Class

发布于 2019-10-04 14:59:23 字数 11134 浏览 991 评论 0 收藏 0

The QDateEdit class provides a date editor. More...

#include <qdatetimeedit.h>

List of all member functions.

Public Members

  • QDateEdit ( QWidget*parent = 0, constchar*name = 0 )
  • QDateEdit ( constQDate&date, QWidget*parent = 0, constchar*name = 0 )
  • ~QDateEdit ()
  • enum Order { DMY, MDY, YMD, YDM }
  • virtual void setDate ( constQDate&date )
  • QDate date () const
  • virtual void setOrder ( Orderorder )
  • Order order () const
  • virtual void setAutoAdvance ( booladvance )
  • bool autoAdvance () const
  • virtual void setMinValue ( constQDate&d )
  • QDate minValue () const
  • virtual void setMaxValue ( constQDate&d )
  • QDate maxValue () const
  • virtual void setRange ( constQDate&min, constQDate&max )
  • QString separator () const
  • virtual void setSeparator ( constQString&s )

Signals

  • void valueChanged ( constQDate&date )

Properties

  • bool autoAdvance- whether the editor automatically advances to the next section
  • QDate date- the date value of the editor
  • QDate maxValue- the maximum editor value
  • QDate minValue- the minimum editor value
  • Order order- the order in which the year, month and day appear

Protected Members

  • virtual QString sectionFormattedText ( intsec )
  • virtual void setYear ( intyear )
  • virtual void setMonth ( intmonth )
  • virtual void setDay ( intday )
  • virtual void fix ()

Protected Slots

  • void updateButtons ()

Detailed Description

The QDateEdit class provides a date editor.

QDateEdit 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 QDateEdit box. Dates appear according the local date/time settings or in year, month, day order if the system doesn't provide this information. It is recommended that the QDateEdit be initialised with a date, e.g.

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

Here we've created a new QDateEdit 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() or setRange().

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

Date Time Widgets

See also QDate, QTimeEdit, QDateTimeEdit, Advanced Widgets and Time and Date.


Member Type Documentation

QDateEdit::Order

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

  • QDateEdit::MDY - month-day-year
  • QDateEdit::DMY - day-month-year
  • QDateEdit::YMD - year-month-day (the default)
  • QDateEdit::YDM - year-day-month (a very bad idea)

Member Function Documentation

QDateEdit::QDateEdit ( QWidget*parent = 0, constchar*name = 0 )

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

QDateEdit::QDateEdit ( constQDate&date, QWidget*parent = 0, constchar*name = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

The date editor is initialized with date.

QDateEdit::~QDateEdit ()

Destroys the object and frees any allocated resources.

bool QDateEdit::autoAdvance () const

Returns TRUE if the editor automatically advances to the next section; otherwise returns FALSE. See the "autoAdvance" property for details.

QDate QDateEdit::date () const

Returns the date value of the editor. See the "date" property for details.

void QDateEdit::fix () [virtual protected]

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 in the range 70..99, the previous century, i.e. 1900, will be added giving a year in the range 1970..1999.
  • If the year has two digits in the range 0..69, the current century, i.e. 2000, will be added giving a year in the range 2000..2069.
  • If the year is in the range 100..999, the current century, i.e. 2000, will be added giving a year in the range 2100..2999.

QDate QDateEdit::maxValue () const

Returns the maximum editor value. See the "maxValue" property for details.

QDate QDateEdit::minValue () const

Returns the minimum editor value. See the "minValue" property for details.

Order QDateEdit::order () const

Returns the order in which the year, month and day appear. See the "order" property for details.

QString QDateEdit::sectionFormattedText ( intsec ) [virtual protected]

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

See also order.

QString QDateEdit::separator () const

Returns the separator for the editor.

void QDateEdit::setAutoAdvance ( booladvance ) [virtual]

Sets whether the editor automatically advances to the next section to advance. See the "autoAdvance" property for details.

void QDateEdit::setDate ( constQDate&date ) [virtual]

Sets the date value of the editor to date. See the "date" property for details.

void QDateEdit::setDay ( intday ) [virtual protected]

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.

void QDateEdit::setMaxValue ( constQDate&d ) [virtual]

Sets the maximum editor value to d. See the "maxValue" property for details.

void QDateEdit::setMinValue ( constQDate&d ) [virtual]

Sets the minimum editor value to d. See the "minValue" property for details.

void QDateEdit::setMonth ( intmonth ) [virtual protected]

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

void QDateEdit::setOrder ( Orderorder ) [virtual]

Sets the order in which the year, month and day appear to order. See the "order" property for details.

void QDateEdit::setRange ( constQDate&min, constQDate&max ) [virtual]

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 QDateEdit::setSeparator ( constQString&s ) [virtual]

Sets the separator to s. Note that currently only the first character of s is used.

void QDateEdit::setYear ( intyear ) [virtual protected]

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

See also QDate.

void QDateEdit::updateButtons () [protected slot]

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

void QDateEdit::valueChanged ( constQDate&date ) [signal]

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


Property Documentation

bool autoAdvance

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.

Set this property's value with setAutoAdvance() and get this property's value with autoAdvance().

QDate date

This property holds the date value of the editor.

If the date property is not valid, the editor displays all zeroes and QDateEdit::date() will return an invalid date. It is strongly recommended that the editor be given a default date value. 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.

Set this property's value with setDate() and get this property's value with date().

QDate maxValue

This property holds the maximum editor value.

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

Set this property's value with setMaxValue() and get this property's value with maxValue().

QDate minValue

This property holds the minimum editor value.

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

Set this property's value with setMinValue() and get this property's value with minValue().

Order order

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

The default order is locale dependent.

See also Order.

Set this property's value with setOrder() and get this property's value with order().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文