Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QDateTimeEdit Class

TheQDateTimeEdit class provides a widget for editing dates and times.More...

Header:#include <QDateTimeEdit>
Inherits:QAbstractSpinBox
Inherited By:

QDateEdit andQTimeEdit

Public Types

enumSection { NoSection, AmPmSection, MSecSection, SecondSection, ..., YearSection }
flagsSections

Properties

Public Functions

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)
boolcalendarPopup() const
QCalendarWidget *calendarWidget() const
voidclearMaximumDate()
voidclearMaximumDateTime()
voidclearMaximumTime()
voidclearMinimumDate()
voidclearMinimumDateTime()
voidclearMinimumTime()
SectioncurrentSection() const
intcurrentSectionIndex() const
QDatedate() const
QDateTimedateTime() const
QStringdisplayFormat() const
SectionsdisplayedSections() const
QDatemaximumDate() const
QDateTimemaximumDateTime() const
QTimemaximumTime() const
QDateminimumDate() const
QDateTimeminimumDateTime() const
QTimeminimumTime() const
SectionsectionAt(int index) const
intsectionCount() const
QStringsectionText(Section section) const
voidsetCalendarPopup(bool enable)
voidsetCalendarWidget(QCalendarWidget * calendarWidget)
voidsetCurrentSection(Section section)
voidsetCurrentSectionIndex(int index)
voidsetDateRange(const QDate & min, const QDate & max)
voidsetDateTimeRange(const QDateTime & min, const QDateTime & max)
voidsetDisplayFormat(const QString & format)
voidsetMaximumDate(const QDate & max)
voidsetMaximumDateTime(const QDateTime & dt)
voidsetMaximumTime(const QTime & max)
voidsetMinimumDate(const QDate & min)
voidsetMinimumDateTime(const QDateTime & dt)
voidsetMinimumTime(const QTime & min)
voidsetSelectedSection(Section section)
voidsetTimeRange(const QTime & min, const QTime & max)
voidsetTimeSpec(Qt::TimeSpec spec)
QTimetime() const
Qt::TimeSpectimeSpec() const

Reimplemented Public Functions

virtual voidclear()
virtual boolevent(QEvent * event)
virtual QSizesizeHint() const
virtual voidstepBy(int steps)

Public Slots

voidsetDate(const QDate & date)
voidsetDateTime(const QDateTime & dateTime)
voidsetTime(const QTime & time)

Signals

voiddateChanged(const QDate & date)
voiddateTimeChanged(const QDateTime & datetime)
voidtimeChanged(const QTime & time)

Protected Functions

virtual QDateTimedateTimeFromText(const QString & text) const
voidinitStyleOption(QStyleOptionSpinBox * option) const
virtual QStringtextFromDateTime(const QDateTime & dateTime) const

Reimplemented Protected Functions

virtual voidfixup(QString & input) const
virtual voidfocusInEvent(QFocusEvent * event)
virtual boolfocusNextPrevChild(bool next)
virtual voidkeyPressEvent(QKeyEvent * event)
virtual voidmousePressEvent(QMouseEvent * event)
virtual voidpaintEvent(QPaintEvent * event)
virtual StepEnabledstepEnabled() const
virtual QValidator::Statevalidate(QString & text, int & pos) const
virtual voidwheelEvent(QWheelEvent * event)

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQDateTimeEdit class provides a widget for editing dates and times.

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 theQDateTimeEdit box. Dates and times appear in accordance with the format set; seesetDisplayFormat().

QDateTimeEdit*dateEdit=newQDateTimeEdit(QDate::currentDate());dateEdit->setMinimumDate(QDate::currentDate().addDays(-365));dateEdit->setMaximumDate(QDate::currentDate().addDays(365));dateEdit->setDisplayFormat("yyyy.MM.dd");

Here we've created a newQDateTimeEdit 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 forQDateTimeEdit is 14 September 1752, and 2 January 4713BC forQDate. You can change this by callingsetMinimumDate(),setMaximumDate(),setMinimumTime(), andsetMaximumTime().

Using a Pop-up Calendar Widget

QDateTimeEdit can be configured to allow aQCalendarWidget to be used to select dates. This is enabled by setting thecalendarPopup property. Additionally, you can supply a custom calendar widget for use as the calendar pop-up by calling thesetCalendarWidget() function. The existing calendar widget can be retrieved withcalendarWidget().

Screenshot of a Windows XP style date time editing widgetA date time editing widget shown in theWindows XP widget style.
Screenshot of a Macintosh style date time editing widgetA date time editing widget shown in theMacintosh widget style.
Screenshot of a Plastique style date time editing widgetA date time editing widget shown in thePlastique widget style.

See alsoQDateEdit,QTimeEdit,QDate, andQTime.

Member Type Documentation

enum QDateTimeEdit::Section
flags QDateTimeEdit::Sections

ConstantValue
QDateTimeEdit::NoSection0x0000
QDateTimeEdit::AmPmSection0x0001
QDateTimeEdit::MSecSection0x0002
QDateTimeEdit::SecondSection0x0004
QDateTimeEdit::MinuteSection0x0008
QDateTimeEdit::HourSection0x0010
QDateTimeEdit::DaySection0x0100
QDateTimeEdit::MonthSection0x0200
QDateTimeEdit::YearSection0x0400

The Sections type is a typedef forQFlags<Section>. It stores an OR combination of Section values.

Property Documentation

calendarPopup :bool

This property holds the current calendar pop-up showing mode.

The calendar pop-up will be shown upon clicking the arrow button. This property is valid only if there is a valid date display format.

This property was introduced in Qt 4.2.

Access functions:

boolcalendarPopup() const
voidsetCalendarPopup(bool enable)

See alsosetDisplayFormat().

currentSection :Section

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

Access functions:

SectioncurrentSection() const
voidsetCurrentSection(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 etc.

setCurrentSection()

This property was introduced in Qt 4.3.

Access functions:

intcurrentSectionIndex() const
voidsetCurrentSectionIndex(int index)

See alsocurrentSection().

date :QDate

This property holds the QDate that is set in the widget.

By default, this property contains a date that refers to January 1, 2000.

Access functions:

QDatedate() const
voidsetDate(const QDate & date)

Notifier signal:

voiddateChanged(const QDate & date)

See alsotime anddateTime.

dateTime :QDateTime

This property holds the QDateTime that is set in the QDateTimeEdit.

When setting this property the timespec of theQDateTimeEdit remains the same and the timespec of the newQDateTime is ignored.

By default, this property contains a date that refers to January 1, 2000 and a time of 00:00:00 and 0 milliseconds.

Access functions:

QDateTimedateTime() const
voidsetDateTime(const QDateTime & dateTime)

Notifier signal:

voiddateTimeChanged(const QDateTime & datetime)

See alsodate andtime.

displayFormat :QString

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 inQDateTime::toString() andQDateTime::fromString()

Example format strings (assuming that the date is 2nd of July 1969):

FormatResult
dd.MM.yyyy02.07.1969
MMM d yyJul 2 69
MMMM d yyJuly 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).

If you specify an invalid format the format will not be set.

Access functions:

QStringdisplayFormat() const
voidsetDisplayFormat(const QString & format)

See alsoQDateTime::toString() anddisplayedSections().

displayedSections : constSections

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

Returns a bit set of the displayed sections for this format.setDisplayFormat(),displayFormat()

Access functions:

SectionsdisplayedSections() const

maximumDate :QDate

This property holds the maximum date of the date time edit.

When setting this property theminimumDate is adjusted if necessary to ensure that the range remains valid. If the date is not a validQDate object, this function does nothing.

By default, this property contains a date that refers to December 31, 7999.

Access functions:

QDatemaximumDate() const
voidsetMaximumDate(const QDate & max)
voidclearMaximumDate()

See alsominimumDate,minimumTime,maximumTime, andsetDateRange().

maximumDateTime :QDateTime

This property holds the maximum datetime of the date time edit.

When setting this property theminimumDateTime() is adjusted if necessary to ensure that the range remains valid. If the datetime is not a validQDateTime 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.

This property was introduced in Qt 4.4.

Access functions:

QDateTimemaximumDateTime() const
voidsetMaximumDateTime(const QDateTime & dt)
voidclearMaximumDateTime()

See alsominimumDateTime(),minimumTime(),maximumTime(),minimumDate(),maximumDate(),setDateTimeRange(),setDateRange(),setTimeRange(),clearMinimumDateTime(),clearMinimumDate(),clearMaximumDate(),clearMinimumTime(), andclearMaximumTime().

maximumTime :QTime

This property holds the maximum time of the date time edit.

When setting this property, theminimumTime is adjusted if necessary to ensure that the range remains valid. If the time is not a validQTime object, this function does nothing.

By default, this property contains a time of 23:59:59 and 999 milliseconds.

Access functions:

QTimemaximumTime() const
voidsetMaximumTime(const QTime & max)
voidclearMaximumTime()

See alsominimumTime,minimumDate,maximumDate, andsetTimeRange().

minimumDate :QDate

This property holds the minimum date of the date time edit.

When setting this property themaximumDate is adjusted if necessary, to ensure that the range remains valid. If the date is not a validQDate 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.

Access functions:

QDateminimumDate() const
voidsetMinimumDate(const QDate & min)
voidclearMinimumDate()

See alsominimumTime(),maximumTime(), andsetDateRange().

minimumDateTime :QDateTime

This property holds the minimum datetime of the date time edit.

When setting this property themaximumDateTime() is adjusted if necessary to ensure that the range remains valid. If the datetime is not a validQDateTime 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.

This property was introduced in Qt 4.4.

Access functions:

QDateTimeminimumDateTime() const
voidsetMinimumDateTime(const QDateTime & dt)
voidclearMinimumDateTime()

See alsomaximumDateTime(),minimumTime(),maximumTime(),minimumDate(),maximumDate(),setDateTimeRange(),setDateRange(),setTimeRange(),clearMaximumDateTime(),clearMinimumDate(),clearMaximumDate(),clearMinimumTime(), andclearMaximumTime().

minimumTime :QTime

This property holds the minimum time of the date time edit.

When setting this property themaximumTime is adjusted if necessary, to ensure that the range remains valid. If the time is not a validQTime object, this function does nothing.

By default, this property contains a time of 00:00:00 and 0 milliseconds.

Access functions:

QTimeminimumTime() const
voidsetMinimumTime(const QTime & min)
voidclearMinimumTime()

See alsomaximumTime,minimumDate,maximumDate, andsetTimeRange().

sectionCount : constint

This property holds the number of sections displayed. If the format is 'yyyy/yy/yyyy', sectionCount returns 3.

This property was introduced in Qt 4.3.

Access functions:

intsectionCount() const

time :QTime

This property holds the QTime that is set in the widget.

By default, this property contains a time of 00:00:00 and 0 milliseconds.

Access functions:

QTimetime() const
voidsetTime(const QTime & time)

Notifier signal:

voidtimeChanged(const QTime & time)

See alsodate anddateTime.

timeSpec :Qt::TimeSpec

This property holds the current timespec used by the date time edit.

This property was introduced in Qt 4.4.

Access functions:

Qt::TimeSpectimeSpec() const
voidsetTimeSpec(Qt::TimeSpec spec)

Member Function Documentation

QDateTimeEdit::QDateTimeEdit(QWidget * parent = 0)

Constructs an empty date time editor with aparent.

QDateTimeEdit::QDateTimeEdit(constQDateTime & datetime,QWidget * parent = 0)

Constructs an empty date time editor with aparent. The value is set todatetime.

QDateTimeEdit::QDateTimeEdit(constQDate & date,QWidget * parent = 0)

Constructs an empty date time editor with aparent. The value is set todate.

QDateTimeEdit::QDateTimeEdit(constQTime & time,QWidget * parent = 0)

Constructs an empty date time editor with aparent. The value is set totime.

QCalendarWidget * QDateTimeEdit::calendarWidget() const

Returns the calendar widget for the editor ifcalendarPopup is set to true and (sections() &DateSections_Mask) != 0.

This function creates and returns a calendar widget if none has been set.

This function was introduced in Qt 4.4.

See alsosetCalendarWidget().

[virtual]void QDateTimeEdit::clear()

Reimplemented fromQAbstractSpinBox::clear().

[virtual protected]QDateTime QDateTimeEdit::dateTimeFromText(constQString & text) const

Returns an appropriate datetime for the giventext.

This virtual function is used by the datetime edit whenever it needs to interpret text entered by the user as a value.

See alsotextFromDateTime() andvalidate().

[virtual]bool QDateTimeEdit::event(QEvent * event)

Reimplemented fromQObject::event().

[virtual protected]void QDateTimeEdit::fixup(QString & input) const

Reimplemented fromQAbstractSpinBox::fixup().

[virtual protected]void QDateTimeEdit::focusInEvent(QFocusEvent * event)

Reimplemented fromQWidget::focusInEvent().

[virtual protected]bool QDateTimeEdit::focusNextPrevChild(bool next)

Reimplemented fromQWidget::focusNextPrevChild().

[protected]void QDateTimeEdit::initStyleOption(QStyleOptionSpinBox * option) const

Initializeoption with the values from this QDataTimeEdit. This method is useful for subclasses when they need aQStyleOptionSpinBox, but don't want to fill in all the information themselves.

See alsoQStyleOption::initFrom().

[virtual protected]void QDateTimeEdit::keyPressEvent(QKeyEvent * event)

Reimplemented fromQWidget::keyPressEvent().

[virtual protected]void QDateTimeEdit::mousePressEvent(QMouseEvent * event)

Reimplemented fromQWidget::mousePressEvent().

[virtual protected]void QDateTimeEdit::paintEvent(QPaintEvent * event)

Reimplemented fromQWidget::paintEvent().

Section QDateTimeEdit::sectionAt(int index) const

Returns the Section atindex.

If the format is 'yyyy/MM/dd', sectionAt(0) returnsYearSection, sectionAt(1) returnsMonthSection, and sectionAt(2) returnsYearSection,

This function was introduced in Qt 4.3.

QString QDateTimeEdit::sectionText(Section section) const

Returns the text from the givensection.

See alsocurrentSection().

void QDateTimeEdit::setCalendarWidget(QCalendarWidget * calendarWidget)

Sets the givencalendarWidget as the widget to be used for the calendar pop-up. The editor does not automatically take ownership of the calendar widget.

Note:calendarPopup must be set to true before setting the calendar widget.

This function was introduced in Qt 4.4.

See alsocalendarWidget() andcalendarPopup.

void QDateTimeEdit::setDateRange(constQDate & min, constQDate & max)

Convenience function to set minimum and maximum date with one function call.

setDateRange(min, max);

is analogous to:

If eithermin ormax are not valid, this function does nothing.

See alsosetMinimumDate(),maximumDate(),setMaximumDate(),clearMinimumDate(),setMinimumTime(),maximumTime(),setMaximumTime(),clearMinimumTime(), andQDate::isValid().

void QDateTimeEdit::setDateTimeRange(constQDateTime & min, constQDateTime & max)

Convenience function to set minimum and maximum date time with one function call.

setDateTimeRange(min, max);

is analogous to:

If eithermin ormax are not valid, this function does nothing.

This function was introduced in Qt 4.4.

See alsosetMinimumDate(),maximumDate(),setMaximumDate(),clearMinimumDate(),setMinimumTime(),maximumTime(),setMaximumTime(),clearMinimumTime(), andQDateTime::isValid().

void QDateTimeEdit::setSelectedSection(Section section)

Selectssection. Ifsection doesn't exist in the currently displayed sections this function does nothing. Ifsection isNoSection this function will unselect all text in the editor. Otherwise this function will move the cursor and the current section to the selected section.

This function was introduced in Qt 4.2.

See alsocurrentSection().

void QDateTimeEdit::setTimeRange(constQTime & min, constQTime & max)

Convenience function to set minimum and maximum time with one function call.

setTimeRange(min, max);

is analogous to:

If eithermin ormax are not valid, this function does nothing.

See alsosetMinimumDate(),maximumDate(),setMaximumDate(),clearMinimumDate(),setMinimumTime(),maximumTime(),setMaximumTime(),clearMinimumTime(), andQTime::isValid().

[virtual]QSize QDateTimeEdit::sizeHint() const

Reimplemented fromQWidget::sizeHint().

[virtual]void QDateTimeEdit::stepBy(int steps)

Reimplemented fromQAbstractSpinBox::stepBy().

[virtual protected]StepEnabled QDateTimeEdit::stepEnabled() const

Reimplemented fromQAbstractSpinBox::stepEnabled().

[virtual protected]QString QDateTimeEdit::textFromDateTime(constQDateTime & dateTime) const

This virtual function is used by the date time edit whenever it needs to displaydateTime.

If you reimplement this, you may also need to reimplementvalidate().

See alsodateTimeFromText() andvalidate().

[virtual protected]QValidator::State QDateTimeEdit::validate(QString & text,int & pos) const

Reimplemented fromQAbstractSpinBox::validate().

[virtual protected]void QDateTimeEdit::wheelEvent(QWheelEvent * event)

Reimplemented fromQWidget::wheelEvent().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp