![]() |
Home |
The QtCalendarWidget class provides a monthly based calendar widget allowing the user to select a date. More...
#include <QtCalendarWidget>
Inherits QWidget.
|
|
The QtCalendarWidget class provides a monthly based calendar widget allowing the user to select a date.
The widget is initialized with the current month and year, but QtCalendarWidget provides several public slots to change the year and month that is shown. The currently displayed month and year can be retrieved using the currentMonth() and currentYear() functions, respectively.
By default, today's date is selected, and the user can select a date using both mouse and keyboard. The currently selected date can be retrieved using the selectedDate() function. It is possible to constrain the user selection to a given date range by setting the minimumDate and maximumDate properties. Alternatively, both properties can be set in one go using the setDateRange() convenience slot. Set the selectable property to false to prohibit the user from selecting at all. Note that a date also can be selected programmatically using the selectDate() slot.
A newly created calendar widget has single letter notation for the days (M for Mondays), and both Sundays and today's date are marked. The calendar table is completed, i.e. days from the previous and next months are added to avoid empty cells, but the calendar grid is not shown. The week numbers are displayed, and the first column day is Sunday.
All this properties can be altered using the corresponding set functions.
The notation of the days can be altered to a longer abbreviation (Mon for Monday) by setting the horizontalHeaderFormat property to QtCalendarWidget::ShortDayNames. Setting the same property to QtCalendarWidget::LongDayNames makes the header display the complete day names. Set the showSundaysInRed and todayMarked properties to false to remove the mark-up colors. To prohibit completing days from the previous and next months, set the completingDaysShown property to false. The week numbers can be removed by setting the verticalHeaderFormat property to QtCalendarWidget::NoVerticalHeader. The calendar grid can be turned on by setting the showGrid property to true using the setShowGrid() function:
QtCalendarWidget *calendar; calendar->setShowGrid(true); |
Finally, the day in the first column can be altered using the setFirstDayOfWeek() function.
The QtCalendarWidget class also provides three signals, selectionChanged(), activated() and currentMonthChanged() making it possible to respond to user interaction.
This enum type defines the various formats the horizontal header can display.
Constant | Value | Description |
---|---|---|
QtCalendarWidget::SingleLetterDayNames | 0 | The header displays a single letter abbreviation for day names (e.g. M for Monday). |
QtCalendarWidget::ShortDayNames | 1 | The header displays a short abbreviation for day names (e.g. Mon for Monday). |
QtCalendarWidget::LongDayNames | 2 | The header displays complete day names (e.g. Monday). |
QtCalendarWidget::NoHorizontalHeader | 3 | The header is hidden. |
See also horizontalHeaderFormat() and VerticalHeaderFormat.
This enum type defines the various formats the vertical header can display.
Constant | Value | Description |
---|---|---|
QtCalendarWidget::ISOWeekNumbers | 0 | The header displays a ISO week numbers QDate::weekNumber(). |
QtCalendarWidget::NoVerticalHeader | 1 | The header is hidden. |
See also verticalHeaderFormat() and HorizontalHeaderFormat.
This property holds whether the calendar table should be filled completely.
When this property is set to true, days from the previous and next month are displayed to fill the calendar table; otherwise there may be empty cells in the top-left and bottom-right corner of the table.
QtCalendarWidget *calendar; calendar->setCompletingDaysShown(true); | QtCalendarWidget *calendar; calendar->setCompletingDaysShown(false); |
The default value is true.
Access functions:
This property holds a value identifying the day displayed in the first column.
By default, the day displayed in the first column is Sunday
Access functions:
This property holds the format of the horizontal header.
The default value is QtCalendarWidget::SingleLetterDayNames.
Access functions:
This property holds the maximum date of the currently specified date range.
The user will not be able to select a date which is after the currently set maximum date.
QtCalendarWidget *calendar; calendar->setShowGrid(true); calendar->setMaximumDate(QDate(2006, 1, 20)); |
By default, the maximum date is the last day the QDate class can handle, i.e. 31. December 7999.
When setting a maximum date, the minimumDate and selectedDate properties are adjusted if the selection range becomes invalid. If the provided date is not a valid QDate object, the setMaximumDate() function does nothing.
Access functions:
See also setDateRange().
This property holds the minimum date of the currently specified date range.
The user will not be able to select a date which is before the currently set minimum date.
QtCalendarWidget *calendar; calendar->setShowGrid(true); calendar->setMinimumDate(QDate(2006, 1, 5)); |
By default, the minimum date is the earliest date that the QDate class can handle, i.e. 14 September 1752.
When setting a minimum date, the maximumDate and selectedDate properties are adjusted if the selection range becomes invalid. If the provided date is not a valid QDate object, the setMinimumDate() function does nothing.
Access functions:
See also setDateRange().
This property holds whether the user can select a date in the calendar.
When this property is set to true the user can select a date within the specified date range, using both mouse and keyboard. Otherwise the user is prohibited from selecting any date.
The default value is true.
Access functions:
This property holds the currently selected date.
The selected date must be within the date range specified by the minimumDate and maximumDate properties. By default, the selected date is the current date.
Access functions:
See also setDateRange().
This property holds whether the table grid is displayed.
![]() |
QtCalendarWidget *calendar; calendar->setShowGrid(true); |
The default value is false.
Access functions:
This property holds whether the Sundays are marked.
When this property is set to true, Sundays are marked with a red color; otherwise they have the same formatting as the other days of the week.
The default value is true.
Access functions:
This property holds whether the current date (today) is marked.
When this property is set to true, the current date is marked with a gray background color; otherwise there is no color background.
The default value is true.
Access functions:
This property holds the format of the vertical header.
The default value is QtCalendarWidget::ISOWeekNumber.
Access functions:
Constructs a calendar widget with the given parent.
The widget is initialized with the current month and year, and the currently selected date is today.
See also setCurrentMonth().
Destroys the calendar widget.
This signal is emitted whenever the user presses the Return or Enter key, the space bar or double-clicks a date in the calendar widget.
Returns the currently displayed month.
See also currentYear() and setCurrentMonth().
This signal is emitted when the currently shown month is changed, passing the new month and year as parameters.
See also setCurrentMonth().
Returns the year of the currently displayed month.
See also currentMonth() and setCurrentMonth().
Shows the next month relative to the currently displayed month. Note that the selected date is not changed.
See also jumpToPreviousMonth(), setCurrentMonth(), and selectDate().
Shows the currently displayed month in the next year relative to the currently displayed year. Note that the selected date is not changed.
See also jumpToPreviousYear(), setCurrentMonth(), and selectDate().
Shows the previous month relative to the currently displayed month. Note that the selected date is not changed.
See also jumpToNextMonth(), setCurrentMonth(), and selectDate().
Shows the currently displayed month in the previous year relative to the currently displayed year. Note that the selected date is not changed.
See also jumpToNextYear(), setCurrentMonth(), and selectDate().
Shows the month of the selected date.
See also selectedDate() and setCurrentMonth().
Shows the month of the today's date.
See also selectedDate() and setCurrentMonth().
This signal is emitted when the currently selected date is changed, passing the new date as parameter.
The currently selected date can be changed by the user using the mouse or keyboard, or by the programmer using the selectDate() function.
See also selectDate().
Displays the given month of the given year without changing the selected date. Use the selectDate() function to alter the selected date.
The currently displayed month and year can be retrieved using the currentMonth() and currentYear() functions respectively.
See also currentMonth(), currentYear(), jumpToPreviousMonth(), jumpToNextMonth(), jumpToPreviousYear(), and jumpToNextYear().
Defines a date range by setting the minimumDate and maximumDate properties.
The date range restricts the user selection, i.e. the user can only select dates within the specified date range. Note that
QtCalendarWidget *calendar; calendar->setDateRange(min, max);
is analogous to
QtCalendarWidget *calendar; calendar->setMinimumDate(min); calendar->setMaximumDate(max);
If either the min or max parameters are not valid QDate objects, this function does nothing.
See also setMinimumDate() and setMaximumDate().
Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Solutions |