Home

QtCalendarWidget Class Reference

The QtCalendarWidget class provides a monthly based calendar widget allowing the user to select a date. More...

#include <QtCalendarWidget>

Inherits QWidget.

Public Types

Properties

Public Functions

Public Slots

Signals

Additional Inherited Members


Detailed Description

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.

See also QDate and QDateEdit.


Member Type Documentation

enum QtCalendarWidget::HorizontalHeaderFormat

This enum type defines the various formats the horizontal header can display.

ConstantValueDescription
QtCalendarWidget::SingleLetterDayNames0The header displays a single letter abbreviation for day names (e.g. M for Monday).
QtCalendarWidget::ShortDayNames1The header displays a short abbreviation for day names (e.g. Mon for Monday).
QtCalendarWidget::LongDayNames2The header displays complete day names (e.g. Monday).
QtCalendarWidget::NoHorizontalHeader3The header is hidden.

See also horizontalHeaderFormat() and VerticalHeaderFormat.

enum QtCalendarWidget::VerticalHeaderFormat

This enum type defines the various formats the vertical header can display.

ConstantValueDescription
QtCalendarWidget::ISOWeekNumbers0The header displays a ISO week numbers QDate::weekNumber().
QtCalendarWidget::NoVerticalHeader1The header is hidden.

See also verticalHeaderFormat() and HorizontalHeaderFormat.


Property Documentation

completingDaysShown : bool

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:

firstDayOfWeek : Qt::DayOfWeek

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:

horizontalHeaderFormat : HorizontalHeaderFormat

This property holds the format of the horizontal header.

The default value is QtCalendarWidget::SingleLetterDayNames.

Access functions:

maximumDate : QDate

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().

minimumDate : QDate

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().

selectable : bool

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:

selectedDate : QDate

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().

showGrid : bool

This property holds whether the table grid is displayed.

    QtCalendarWidget *calendar;

    calendar->setShowGrid(true);

The default value is false.

Access functions:

showSundaysInRed : bool

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:

todayMarked : bool

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:

verticalHeaderFormat : VerticalHeaderFormat

This property holds the format of the vertical header.

The default value is QtCalendarWidget::ISOWeekNumber.

Access functions:


Member Function Documentation

QtCalendarWidget::QtCalendarWidget ( QWidget * parent = 0 )

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().

QtCalendarWidget::~QtCalendarWidget ()

Destroys the calendar widget.

void QtCalendarWidget::activated ( const QDate & date )   [signal]

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.

int QtCalendarWidget::currentMonth () const

Returns the currently displayed month.

See also currentYear() and setCurrentMonth().

void QtCalendarWidget::currentMonthChanged ( int year, int month )   [signal]

This signal is emitted when the currently shown month is changed, passing the new month and year as parameters.

See also setCurrentMonth().

int QtCalendarWidget::currentYear () const

Returns the year of the currently displayed month.

See also currentMonth() and setCurrentMonth().

void QtCalendarWidget::jumpToNextMonth ()   [slot]

Shows the next month relative to the currently displayed month. Note that the selected date is not changed.

See also jumpToPreviousMonth(), setCurrentMonth(), and selectDate().

void QtCalendarWidget::jumpToNextYear ()   [slot]

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().

void QtCalendarWidget::jumpToPreviousMonth ()   [slot]

Shows the previous month relative to the currently displayed month. Note that the selected date is not changed.

See also jumpToNextMonth(), setCurrentMonth(), and selectDate().

void QtCalendarWidget::jumpToPreviousYear ()   [slot]

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().

void QtCalendarWidget::jumpToSelectedDate ()   [slot]

Shows the month of the selected date.

See also selectedDate() and setCurrentMonth().

void QtCalendarWidget::jumpToToday ()   [slot]

Shows the month of the today's date.

See also selectedDate() and setCurrentMonth().

void QtCalendarWidget::selectionChanged ( const QDate & date )   [signal]

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().

void QtCalendarWidget::setCurrentMonth ( int year, int month )   [slot]

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().

void QtCalendarWidget::setDateRange ( const QDate & min, const QDate & max )   [slot]

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