|  | Home · All Classes · Modules

# QCalendarWidget Class Reference
[QtGui module]

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

Inherits QWidget.

### Types

- enum HorizontalHeaderFormat { NoHorizontalHeader, SingleLetterDayNames, ShortDayNames, LongDayNames }
- enum SelectionMode { NoSelection, SingleSelection }
- enum VerticalHeaderFormat { NoVerticalHeader, ISOWeekNumbers }

### Methods

- __init__ (self, QWidget parent = None)
- int dateEditAcceptDelay (self)
- dict-of-QDate-QTextCharFormat dateTextFormat (self)
- QTextCharFormat dateTextFormat (self, QDate)
- bool event (self, QEvent)
- bool eventFilter (self, QObject, QEvent)
- Qt.DayOfWeek firstDayOfWeek (self)
- QTextCharFormat headerTextFormat (self)
- HorizontalHeaderFormat horizontalHeaderFormat (self)
- bool isDateEditEnabled (self)
- bool isGridVisible (self)
- bool isHeaderVisible (self)
- bool isNavigationBarVisible (self)
- keyPressEvent (self, QKeyEvent)
- QDate maximumDate (self)
- QDate minimumDate (self)
- QSize minimumSizeHint (self)
- int monthShown (self)
- mousePressEvent (self, QMouseEvent)
- paintCell (self, QPainter, QRect, QDate)
- resizeEvent (self, QResizeEvent)
- QDate selectedDate (self)
- SelectionMode selectionMode (self)
- setCurrentPage (self, int, int)
- setDateEditAcceptDelay (self, int)
- setDateEditEnabled (self, bool)
- setDateRange (self, QDate, QDate)
- setDateTextFormat (self, QDate, QTextCharFormat)
- setFirstDayOfWeek (self, Qt.DayOfWeek)
- setGridVisible (self, bool)
- setHeaderTextFormat (self, QTextCharFormat)
- setHeaderVisible (self, bool)
- setHorizontalHeaderFormat (self, HorizontalHeaderFormat)
- setMaximumDate (self, QDate)
- setMinimumDate (self, QDate)
- setNavigationBarVisible (self, bool)
- setSelectedDate (self, QDate)
- setSelectionMode (self, SelectionMode)
- setVerticalHeaderFormat (self, VerticalHeaderFormat)
- setWeekdayTextFormat (self, Qt.DayOfWeek, QTextCharFormat)
- showNextMonth (self)
- showNextYear (self)
- showPreviousMonth (self)
- showPreviousYear (self)
- showSelectedDate (self)
- showToday (self)
- QSize sizeHint (self)
- updateCell (self, QDate)
- updateCells (self)
- VerticalHeaderFormat verticalHeaderFormat (self)
- QTextCharFormat weekdayTextFormat (self, Qt.DayOfWeek)
- int yearShown (self)

### Qt Signals

- void activated (const QDate&)
- void clicked (const QDate&)
- void currentPageChanged (int,int)
- void selectionChanged ()

## Detailed Description

The QCalendarWidget 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 QCalendarWidget provides several public slots to change the year and month that is shown.

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 selectionMode property to NoSelection to prohibit the user from selecting at all. Note that a date also can be selected programmatically using the setSelectedDate() slot.

The currently displayed month and year can be retrieved using the monthShown() and yearShown() functions, respectively.

A newly created calendar widget uses abbreviated day names, and both Saturdays and Sundays are marked in red. The calendar grid is not visible. The week numbers are displayed, and the first column day is Sunday.

The notation of the days can be altered to a single letter abbreviations ("M" for "Monday") by setting the horizontalHeaderFormat property to QCalendarWidget.SingleLetterDayNames. Setting the same property to QCalendarWidget.LongDayNames makes the header display the complete day names. The week numbers can be removed by setting the verticalHeaderFormat property to QCalendarWidget.NoVerticalHeader. The calendar grid can be turned on by setting the gridVisible property to true using the setGridVisible() function:

     QCalendarWidget *calendar;
     calendar->setGridVisible(true);

Finally, the day in the first column can be altered using the setFirstDayOfWeek() function.

The QCalendarWidget class also provides three signals, selectionChanged(), activated() and currentPageChanged() making it possible to respond to user interaction.

The rendering of the headers, weekdays or single days can be largely customized by setting QTextCharFormat's for some special weekday, a special date or for the rendering of the headers.

Only a subset of the properties in QTextCharFormat are used by the calendar widget. Currently, the foreground, background and font properties are used to determine the rendering of individual cells in the widget.

See also QDate, QDateEdit, and QTextCharFormat.

## Type Documentation

### QCalendarWidget.HorizontalHeaderFormat

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

Constant | Value | Description
--- | --- | ---
`QCalendarWidget.SingleLetterDayNames` | `1` | The header displays a single letter abbreviation for day names (e.g. M for Monday).
`QCalendarWidget.ShortDayNames` | `2` | The header displays a short abbreviation for day names (e.g. Mon for Monday).
`QCalendarWidget.LongDayNames` | `3` | The header displays complete day names (e.g. Monday).
`QCalendarWidget.NoHorizontalHeader` | `0` | The header is hidden.

See also horizontalHeaderFormat() and VerticalHeaderFormat.

### QCalendarWidget.SelectionMode

This enum describes the types of selection offered to the user for selecting dates in the calendar.

Constant | Value | Description
--- | --- | ---
`QCalendarWidget.NoSelection` | `0` | Dates cannot be selected.
`QCalendarWidget.SingleSelection` | `1` | Single dates can be selected.

See also selectionMode.

### QCalendarWidget.VerticalHeaderFormat

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

Constant | Value | Description
--- | --- | ---
`QCalendarWidget.ISOWeekNumbers` | `1` | The header displays ISO week numbers as described by QDate.weekNumber().
`QCalendarWidget.NoVerticalHeader` | `0` | The header is hidden.

See also verticalHeaderFormat() and HorizontalHeaderFormat.

## Method Documentation

### QCalendarWidget.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

### int QCalendarWidget.dateEditAcceptDelay (self)

### dict-of-QDate-QTextCharFormat QCalendarWidget.dateTextFormat (self)

Returns a QMap from QDate to QTextCharFormat showing all dates that use a special format that alters their rendering.

See also setDateTextFormat().

### QTextCharFormat QCalendarWidget.dateTextFormat (self, QDate)

Returns a QTextCharFormat for date. The char format can be be empty if the date is not renderd specially.

### bool QCalendarWidget.event (self, QEvent)

Reimplemented from QObject.event().

### bool QCalendarWidget.eventFilter (self, QObject, QEvent)

Reimplemented from QObject.eventFilter().

### Qt.DayOfWeek QCalendarWidget.firstDayOfWeek (self)

### QTextCharFormat QCalendarWidget.headerTextFormat (self)

Returns the text char format for rendering the header.

See also setHeaderTextFormat().

### HorizontalHeaderFormat QCalendarWidget.horizontalHeaderFormat (self)

### bool QCalendarWidget.isDateEditEnabled (self)

### bool QCalendarWidget.isGridVisible (self)

### bool QCalendarWidget.isHeaderVisible (self)

### bool QCalendarWidget.isNavigationBarVisible (self)

### QCalendarWidget.keyPressEvent (self, QKeyEvent)

Reimplemented from QWidget.keyPressEvent().

### QDate QCalendarWidget.maximumDate (self)

### QDate QCalendarWidget.minimumDate (self)

### QSize QCalendarWidget.minimumSizeHint (self)

Reimplemented from QWidget.minimumSizeHint().

### int QCalendarWidget.monthShown (self)

Returns the currently displayed month. Months are numbered from 1 to 12.

See also yearShown() and setCurrentPage().

### QCalendarWidget.mousePressEvent (self, QMouseEvent)

Reimplemented from QWidget.mousePressEvent().

### QCalendarWidget.paintCell (self, QPainter, QRect, QDate)

Paints the cell specified by the given date, using the given painter and rect.

### QCalendarWidget.resizeEvent (self, QResizeEvent)

Reimplemented from QWidget.resizeEvent().

### QDate QCalendarWidget.selectedDate (self)

### SelectionMode QCalendarWidget.selectionMode (self)

### QCalendarWidget.setCurrentPage (self, int, int)

This method is also a Qt slot with the C++ signature `void setCurrentPage(int,int)`.

Displays the given month of the given year without changing the selected date. Use the setSelectedDate() function to alter the selected date.

The currently displayed month and year can be retrieved using the monthShown() and yearShown() functions respectively.

See also yearShown(), monthShown(), showPreviousMonth(), showNextMonth(), showPreviousYear(), and showNextYear().

### QCalendarWidget.setDateEditAcceptDelay (self, int)

### QCalendarWidget.setDateEditEnabled (self, bool)

### QCalendarWidget.setDateRange (self, QDate, QDate)

This method is also a Qt slot with the C++ signature `void setDateRange(const QDate&,const QDate&)`.

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

     QCalendarWidget *calendar;

     calendar->setDateRange(min, max);

is analogous to

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

### QCalendarWidget.setDateTextFormat (self, QDate, QTextCharFormat)

Sets the format used to render the given date to that specified by format.

If date is null, all date formats are cleared.

See also dateTextFormat().

### QCalendarWidget.setFirstDayOfWeek (self, Qt.DayOfWeek)

### QCalendarWidget.setGridVisible (self, bool)

### QCalendarWidget.setHeaderTextFormat (self, QTextCharFormat)

Sets the text char format for rendering the header to format. If you also set a weekday text format, this format's foreground and background color will take precedence over the header's format. The other formatting information will still be decided by the header's format.

See also headerTextFormat().

### QCalendarWidget.setHeaderVisible (self, bool)

### QCalendarWidget.setHorizontalHeaderFormat (self, HorizontalHeaderFormat)

### QCalendarWidget.setMaximumDate (self, QDate)

### QCalendarWidget.setMinimumDate (self, QDate)

### QCalendarWidget.setNavigationBarVisible (self, bool)

This method is also a Qt slot with the C++ signature `void setNavigationBarVisible(bool)`.

### QCalendarWidget.setSelectedDate (self, QDate)

This method is also a Qt slot with the C++ signature `void setSelectedDate(const QDate&)`.

### QCalendarWidget.setSelectionMode (self, SelectionMode)

### QCalendarWidget.setVerticalHeaderFormat (self, VerticalHeaderFormat)

### QCalendarWidget.setWeekdayTextFormat (self, Qt.DayOfWeek, QTextCharFormat)

Sets the text char format for rendering of day in the week dayOfWeek to format. The format will take precedence over the header format in case of foreground and background color. Other text formatting information is taken from the headers format.

See also weekdayTextFormat() and setHeaderTextFormat().

### QCalendarWidget.showNextMonth (self)

This method is also a Qt slot with the C++ signature `void showNextMonth()`.

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

See also showPreviousMonth(), setCurrentPage(), and setSelectedDate().

### QCalendarWidget.showNextYear (self)

This method is also a Qt slot with the C++ signature `void showNextYear()`.

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 showPreviousYear(), setCurrentPage(), and setSelectedDate().

### QCalendarWidget.showPreviousMonth (self)

This method is also a Qt slot with the C++ signature `void showPreviousMonth()`.

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

See also showNextMonth(), setCurrentPage(), and setSelectedDate().

### QCalendarWidget.showPreviousYear (self)

This method is also a Qt slot with the C++ signature `void showPreviousYear()`.

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 showNextYear(), setCurrentPage(), and setSelectedDate().

### QCalendarWidget.showSelectedDate (self)

This method is also a Qt slot with the C++ signature `void showSelectedDate()`.

Shows the month of the selected date.

See also selectedDate() and setCurrentPage().

### QCalendarWidget.showToday (self)

This method is also a Qt slot with the C++ signature `void showToday()`.

Shows the month of the today's date.

See also selectedDate() and setCurrentPage().

### QSize QCalendarWidget.sizeHint (self)

Reimplemented from QWidget.sizeHint().

### QCalendarWidget.updateCell (self, QDate)

Updates the cell specified by the given date unless updates are disabled or the cell is hidden.

This function was introduced in Qt 4.4.

See also updateCells(), yearShown(), and monthShown().

### QCalendarWidget.updateCells (self)

Updates all visible cells unless updates are disabled.

This function was introduced in Qt 4.4.

See also updateCell().

### VerticalHeaderFormat QCalendarWidget.verticalHeaderFormat (self)

### QTextCharFormat QCalendarWidget.weekdayTextFormat (self, Qt.DayOfWeek)

Returns the text char format for rendering of day in the week dayOfWeek.

See also setWeekdayTextFormat() and headerTextFormat().

### int QCalendarWidget.yearShown (self)

Returns the year of the currently displayed month. Months are numbered from 1 to 12.

See also monthShown() and setCurrentPage().

## Qt Signal Documentation

### void activated (const QDate&)

This is the default overload of this signal.

This signal is emitted whenever the user presses the Return or Enter key or double-clicks a date in the calendar widget.

### void clicked (const QDate&)

This is the default overload of this signal.

This signal is emitted when a mouse button is clicked. The date the mouse was clicked on is specified by date. The signal is only emitted when clicked on a valid date, e.g., dates are not outside the minimumDate() and maximumDate(). If the selection mode is NoSelection, this signal will not be emitted.

### void currentPageChanged (int,int)

This is the default overload of this signal.

This signal is emitted when the currently shown month is changed. The new year and month are passed as parameters.

See also setCurrentPage().

### void selectionChanged ()

This is the default overload of this signal.

This signal is emitted when the currently selected date is changed.

The currently selected date can be changed by the user using the mouse or keyboard, or by the programmer using setSelectedDate().

See also selectedDate().