返回介绍

QTimeEdit Class

发布于 2019-10-04 15:03:25 字数 8353 浏览 1205 评论 0 收藏 0

The QTimeEdit class provides a time editor. More...

#include <qdatetimeedit.h>

List of all member functions.

Public Members

  • QTimeEdit ( QWidget*parent = 0, constchar*name = 0 )
  • QTimeEdit ( constQTime&time, QWidget*parent = 0, constchar*name = 0 )
  • ~QTimeEdit ()
  • virtual void setTime ( constQTime&time )
  • QTime time () const
  • virtual void setAutoAdvance ( booladvance )
  • bool autoAdvance () const
  • virtual void setMinValue ( constQTime&d )
  • QTime minValue () const
  • virtual void setMaxValue ( constQTime&d )
  • QTime maxValue () const
  • virtual void setRange ( constQTime&min, constQTime&max )
  • QString separator () const
  • virtual void setSeparator ( constQString&s )

Signals

  • void valueChanged ( constQTime&time )

Properties

  • bool autoAdvance- whether the editor automatically advances to the next section
  • QTime maxValue- the maximum time value
  • QTime minValue- the minimum time value
  • QTime time- the time value of the editor

Protected Members

  • virtual QString sectionFormattedText ( intsec )
  • virtual void setHour ( inth )
  • virtual void setMinute ( intm )
  • virtual void setSecond ( ints )

Protected Slots

  • void updateButtons ()

Detailed Description

The QTimeEdit class provides a time editor.

QTimeEdit allows the user to edit times by using the keyboard or the arrow keys to increase/decrease time values. The arrow keys can be used to move from section to section within the QTimeEdit box. The user can automatically be moved to the next section once they complete a section using setAutoAdvance(). Times appear in hour, minute, second order. It is recommended that the QTimeEdit be initialised with a time, e.g.

    QTime timeNow = QTime::currentTime();
    QTimeEdit *timeEdit = new QTimeEdit( timeNow, this );
    timeEdit->setRange( timeNow, timeNow.addSecs( 60 * 60 ) );
    
Here we've created a QTimeEdit widget set to the current time. We've also set the minimum value to the current time and the maximum time to one hour from now.

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

Terminology: A QTimeWidget consists of three sections, one each for the hour, minute and second. You can change the separator character using setSeparator(), by default the separator is read from the system's settings.

Date Time Widgets

See also QTime, QDateEdit, QDateTimeEdit, Advanced Widgets and Time and Date.


Member Function Documentation

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

Constructs an empty time edit with parent parent and name name.

QTimeEdit::QTimeEdit ( constQTime&time, QWidget*parent = 0, constchar*name = 0 )

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

Constructs a time edit with the initial time value, time, parent parent and name name.

QTimeEdit::~QTimeEdit ()

Destroys the object and frees any allocated resources.

bool QTimeEdit::autoAdvance () const

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

QTime QTimeEdit::maxValue () const

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

QTime QTimeEdit::minValue () const

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

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

Returns the formatted number for section sec. This will correspond to either the hour, minute or second section, depending on sec.

QString QTimeEdit::separator () const

Returns the separator for the editor.

void QTimeEdit::setAutoAdvance ( booladvance ) [virtual]

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

void QTimeEdit::setHour ( inth ) [virtual protected]

Sets the hour to h, which must be a valid hour, i.e. in the range 0..24.

void QTimeEdit::setMaxValue ( constQTime&d ) [virtual]

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

void QTimeEdit::setMinValue ( constQTime&d ) [virtual]

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

void QTimeEdit::setMinute ( intm ) [virtual protected]

Sets the minute to m, which must be a valid minute, i.e. in the range 0..59.

void QTimeEdit::setRange ( constQTime&min, constQTime&max ) [virtual]

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

void QTimeEdit::setSecond ( ints ) [virtual protected]

Sets the second to s, which must be a valid second, i.e. in the range 0..59.

void QTimeEdit::setSeparator ( constQString&s ) [virtual]

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

void QTimeEdit::setTime ( constQTime&time ) [virtual]

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

QTime QTimeEdit::time () const

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

void QTimeEdit::updateButtons () [protected slot]

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

void QTimeEdit::valueChanged ( constQTime&time ) [signal]

This signal is emitted whenever the editor's value changes. The time 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 time 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().

QTime maxValue

This property holds the maximum time value.

Setting the maximum time value is equivalent to calling QTimeEdit::setRange( minValue(), t ), where t is the maximum time. The default maximum time is 23:59:59.

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

QTime minValue

This property holds the minimum time value.

Setting the minimum time value is equivalent to calling QTimeEdit::setRange( t, maxValue() ), where t is the minimum time. The default minimum time is 00:00:00.

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

QTime time

This property holds the time value of the editor.

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

Set this property's value with setTime() and get this property's value with time().

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

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

发布评论

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