QDateTimeEdit Class Reference
|
|
|
The QDateTimeEdit 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 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, and 2 January 4713BC for QDate. You can change this by calling setMinimumDate(), setMaximumDate(), setMinimumTime(), and setMaximumTime().
QDateTimeEdit can be configured to allow a QCalendarWidget to be used to select dates. This is enabled by setting the calendarPopup property. Additionally, you can supply a custom calendar widget for use as the calendar pop-up by calling the setCalendarWidget() function. The existing calendar widget can be retrieved with calendarWidget().
A date time editing widget shown in the Windows XP widget style. | |
A date time editing widget shown in the Macintosh widget style. | |
A date time editing widget shown in the Plastique widget style. |
See also QDateEdit, QTimeEdit, QDate, and QTime.
Constant | Value |
---|---|
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 |
The Sections type is a typedef for QFlags<Section>. It stores an OR combination of Section values.
This property holds the current calender 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:
See also setDisplayFormat().
This property holds the current section of the spinbox setCurrentSection().
Access functions:
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:
See also currentSection().
This property holds the QDate that is set in the QDateTimeEdit.
By default, this property contains a date that refers to January 1, 2000.
Access functions:
This property holds the QDateTime that is set in the QDateTimeEdit.
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:
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 in QDateTime::toString() and QDateTime::fromString()
Example format strings(assuming that the date is 2nd of July 1969):
Format | Result |
---|---|
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).
If you specify an invalid format the format will not be set.
Access functions:
See also QDateTime::toString() and displayedSections().
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:
This property holds the maximum date of the date time edit.
When setting this property the 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.
Access functions:
See also minimumDate, minimumTime, maximumTime, and setDateRange().
This property holds the maximum datetime of the date time edit.
When setting this property the 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.
This property was introduced in Qt 4.4.
Access functions:
See also minimumDateTime(), minimumTime(), maximumTime(), minimumDate(), maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(), clearMinimumDateTime(), clearMinimumDate(), clearMaximumDate(), clearMinimumTime(), and clearMaximumTime().
This property holds the maximum time of the date time edit.
When setting this property, the 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.
Access functions:
See also minimumTime, minimumDate, maximumDate, and setTimeRange().
This property holds the minimum date of the date time edit.
When setting this property the 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.
Access functions:
See also minimumTime(), maximumTime(), and setDateRange().
This property holds the minimum datetime of the date time edit.
When setting this property the 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.
This property was introduced in Qt 4.4.
Access functions:
See also maximumDateTime(), minimumTime(), maximumTime(), minimumDate(), maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(), clearMaximumDateTime(), clearMinimumDate(), clearMaximumDate(), clearMinimumTime(), and clearMaximumTime().
This property holds the minimum time of the date time edit.
When setting this property the 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.
By default, this property contains a time of 00:00:00 and 0 milliseconds.
Access functions:
See also maximumTime, minimumDate, maximumDate, and setTimeRange().
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:
This property holds the QTime that is set in the QDateTimeEdit.
By default, this property contains a time of 00:00:00 and 0 milliseconds.
Access functions:
This property holds the current timespec used by the date time edit.
All dates/passed to the date time edit will be converted to this timespec.
This property was introduced in Qt 4.4.
Access functions:
Constructs an empty date time editor with a parent.
Constructs an empty date time editor with a parent. The value is set to datetime.
Constructs an empty date time editor with a parent. The value is set to date.
Constructs an empty date time editor with a parent. The value is set to time.
Returns the calendar widget for the editor if calendarPopup 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 also setCalendarWidget().
This signal is emitted whenever the date is changed. The new date is passed in date.
This signal is emitted whenever the date or time is changed. The new date and time is passed in datetime.
Returns an appropriate datetime for the given text.
This virtual function is used by the datetime edit whenever it needs to interpret text entered by the user as a value.
See also textFromDateTime() and validate().
Initialize option with the values from this QDataTimeEdit. This method is useful for subclasses when they need a QStyleOptionSpinBox, but don't want to fill in all the information themselves.
See also QStyleOption::initFrom().
Returns the Section at index.
If the format is 'yyyy/MM/dd', sectionAt(0) returns YearSection, sectionAt(1) returns MonthSection, and sectionAt(2) returns YearSection,
This function was introduced in Qt 4.3.
Returns the text from the given section.
See also currentSection().
Sets the given calendarWidget as the widget to be used for the calendar pop-up. The editor does not automatically take ownership of the calendar widget.
This function was introduced in Qt 4.4.
See also calendarWidget() and calendarPopup.
Convenience function to set minimum and maximum date with one function call.
setDateRange(min, max);
is analogous to:
setMinimumDate(min); setMaximumDate(max);
If either min or max are not valid, this function does nothing.
See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QDate::isValid().
Convenience function to set minimum and maximum date time with one function call.
setDateTimeRange(min, max);
is analogous to:
setMinimumDateTime(min); setMaximumDateTime(max);
If either min or max are not valid, this function does nothing.
This function was introduced in Qt 4.4.
See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QDateTime::isValid().
Selects section. If section doesn't exist in the currently displayed sections this function does nothing. If section is NoSection 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 also currentSection().
Convenience function to set minimum and maximum time with one function call.
setTimeRange(min, max);
is analogous to:
setMinimumTime(min); setMaximumTime(max);
If either min or max are not valid, this function does nothing.
See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QTime::isValid().
This virtual function is used by the date time edit whenever it needs to display dateTime.
If you reimplement this, you may also need to reimplement validate().
See also dateTimeFromText() and validate().
This signal is emitted whenever the time is changed. The new time is passed in time.
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.5.2 |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |