QCalendarWidget

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

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

../../_images/cleanlooks-calendarwidget.png

The widget is initialized with the current month and year, but PySide.QtGui.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 PySide.QtGui.QCalendarWidget.selectedDate() function. It is possible to constrain the user selection to a given date range by setting the PySide.QtGui.QCalendarWidget.minimumDate() and PySide.QtGui.QCalendarWidget.maximumDate() properties. Alternatively, both properties can be set in one go using the PySide.QtGui.QCalendarWidget.setDateRange() convenience slot. Set the PySide.QtGui.QCalendarWidget.selectionMode() property to NoSelection to prohibit the user from selecting at all. Note that a date also can be selected programmatically using the PySide.QtGui.QCalendarWidget.setSelectedDate() slot.

The currently displayed month and year can be retrieved using the PySide.QtGui.QCalendarWidget.monthShown() and PySide.QtGui.QCalendarWidget.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 PySide.QtGui.QCalendarWidget.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 PySide.QtGui.QCalendarWidget.verticalHeaderFormat() property to QCalendarWidget.NoVerticalHeader . The calendar grid can be turned on by setting the gridVisible() property to true using the PySide.QtGui.QCalendarWidget.setGridVisible() function:

../../_images/qcalendarwidget-grid.png
calendar.setGridVisible(True)

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

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

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

Only a subset of the properties in PySide.QtGui.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.

class PySide.QtGui.QCalendarWidget([parent=None])
Parameters:parentPySide.QtGui.QWidget

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.

PySide.QtGui.QCalendarWidget.HorizontalHeaderFormat

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

Constant Description
QCalendarWidget.SingleLetterDayNames The header displays a single letter abbreviation for day names (e.g. M for Monday).
QCalendarWidget.ShortDayNames The header displays a short abbreviation for day names (e.g. Mon for Monday).
QCalendarWidget.LongDayNames The header displays complete day names (e.g. Monday).
QCalendarWidget.NoHorizontalHeader The header is hidden.

See also

PySide.QtGui.QCalendarWidget.horizontalHeaderFormat() QCalendarWidget.VerticalHeaderFormat

PySide.QtGui.QCalendarWidget.VerticalHeaderFormat

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

Constant Description
QCalendarWidget.ISOWeekNumbers The header displays ISO week numbers as described by QDate.weekNumber() .
QCalendarWidget.NoVerticalHeader The header is hidden.

See also

PySide.QtGui.QCalendarWidget.verticalHeaderFormat() QCalendarWidget.HorizontalHeaderFormat

PySide.QtGui.QCalendarWidget.SelectionMode

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

Constant Description
QCalendarWidget.NoSelection Dates cannot be selected.
QCalendarWidget.SingleSelection Single dates can be selected.
PySide.QtGui.QCalendarWidget.activated(date)
Parameters:datePySide.QtCore.QDate
PySide.QtGui.QCalendarWidget.clicked(date)
Parameters:datePySide.QtCore.QDate
PySide.QtGui.QCalendarWidget.currentPageChanged(year, month)
Parameters:
  • yearPySide.QtCore.int
  • monthPySide.QtCore.int
PySide.QtGui.QCalendarWidget.dateEditAcceptDelay()
Return type:PySide.QtCore.int

This property holds the time an inactive date edit is shown before its contents are accepted.

If the calendar widget’s date edit is enabled , this property specifies the amount of time (in millseconds) that the date edit remains open after the most recent user input. Once this time has elapsed, the date specified in the date edit is accepted and the popup is closed.

By default, the delay is defined to be 1500 milliseconds (1.5 seconds).

PySide.QtGui.QCalendarWidget.dateTextFormat()
Return type:

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

PySide.QtGui.QCalendarWidget.dateTextFormat(date)
Parameters:datePySide.QtCore.QDate
Return type:PySide.QtGui.QTextCharFormat

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

PySide.QtGui.QCalendarWidget.firstDayOfWeek()
Return type:PySide.QtCore.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

PySide.QtGui.QCalendarWidget.headerTextFormat()
Return type:PySide.QtGui.QTextCharFormat

Returns the text char format for rendering the header.

PySide.QtGui.QCalendarWidget.horizontalHeaderFormat()
Return type:PySide.QtGui.QCalendarWidget.HorizontalHeaderFormat

This property holds the format of the horizontal header..

The default value is QCalendarWidget.ShortDayNames .

PySide.QtGui.QCalendarWidget.isDateEditEnabled()
Return type:PySide.QtCore.bool

This property holds whether the date edit popup is enabled.

If this property is enabled, pressing a non-modifier key will cause a date edit to popup if the calendar widget has focus, allowing the user to specify a date in the form specified by the current locale.

By default, this property is enabled.

The date edit is simpler in appearance than PySide.QtGui.QDateEdit , but allows the user to navigate between fields using the left and right cursor keys, increment and decrement individual fields using the up and down cursor keys, and enter values directly using the number keys.

PySide.QtGui.QCalendarWidget.isGridVisible()
Return type:PySide.QtCore.bool

This property holds whether the table grid is displayed..

../../_images/qcalendarwidget-grid.png
calendar.setGridVisible(True)

The default value is false.

PySide.QtGui.QCalendarWidget.isNavigationBarVisible()
Return type:PySide.QtCore.bool

This property holds whether the navigation bar is shown or not.

When this property is true (the default), the next month, previous month, month selection, year selection controls are shown on top.

When the property is set to false, these controls are hidden.

PySide.QtGui.QCalendarWidget.maximumDate()
Return type:PySide.QtCore.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.

../../_images/qcalendarwidget-maximum.png
calendar.setGridVisible(True)
calendar.setMaximumDate(QDate(2006, 7, 3))

By default, the maximum date is the last day the PySide.QtCore.QDate class can handle.

When setting a maximum date, the PySide.QtGui.QCalendarWidget.minimumDate() and PySide.QtGui.QCalendarWidget.selectedDate() properties are adjusted if the selection range becomes invalid. If the provided date is not a valid PySide.QtCore.QDate object, the PySide.QtGui.QCalendarWidget.setMaximumDate() function does nothing.

PySide.QtGui.QCalendarWidget.minimumDate()
Return type:PySide.QtCore.QDate

This property holds the minimum date of the currently specified date range..

The user will not be able to select a date that is before the currently set minimum date.

../../_images/qcalendarwidget-minimum.png
calendar.setGridVisible(True)
calendar.setMinimumDate(QDate(2006, 6, 19))

By default, the minimum date is the earliest date that the PySide.QtCore.QDate class can handle.

When setting a minimum date, the PySide.QtGui.QCalendarWidget.maximumDate() and PySide.QtGui.QCalendarWidget.selectedDate() properties are adjusted if the selection range becomes invalid. If the provided date is not a valid PySide.QtCore.QDate object, the PySide.QtGui.QCalendarWidget.setMinimumDate() function does nothing.

PySide.QtGui.QCalendarWidget.monthShown()
Return type:PySide.QtCore.int

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

PySide.QtGui.QCalendarWidget.paintCell(painter, rect, date)
Parameters:

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

PySide.QtGui.QCalendarWidget.selectedDate()
Return type:PySide.QtCore.QDate

This property holds the currently selected date..

The selected date must be within the date range specified by the PySide.QtGui.QCalendarWidget.minimumDate() and PySide.QtGui.QCalendarWidget.maximumDate() properties. By default, the selected date is the current date.

PySide.QtGui.QCalendarWidget.selectionChanged()
PySide.QtGui.QCalendarWidget.selectionMode()
Return type:PySide.QtGui.QCalendarWidget.SelectionMode

This property holds the type of selection the user can make in the calendar.

When this property is set to SingleSelection , the user can select a date within the minimum and maximum allowed dates, using either the mouse or the keyboard.

When the property is set to NoSelection , the user will be unable to select dates, but they can still be selected programmatically. Note that the date that is selected when the property is set to NoSelection will still be the selected date of the calendar.

The default value is SingleSelection .

PySide.QtGui.QCalendarWidget.setCurrentPage(year, month)
Parameters:
  • yearPySide.QtCore.int
  • monthPySide.QtCore.int

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

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

PySide.QtGui.QCalendarWidget.setDateEditAcceptDelay(delay)
Parameters:delayPySide.QtCore.int

This property holds the time an inactive date edit is shown before its contents are accepted.

If the calendar widget’s date edit is enabled , this property specifies the amount of time (in millseconds) that the date edit remains open after the most recent user input. Once this time has elapsed, the date specified in the date edit is accepted and the popup is closed.

By default, the delay is defined to be 1500 milliseconds (1.5 seconds).

PySide.QtGui.QCalendarWidget.setDateEditEnabled(enable)
Parameters:enablePySide.QtCore.bool

This property holds whether the date edit popup is enabled.

If this property is enabled, pressing a non-modifier key will cause a date edit to popup if the calendar widget has focus, allowing the user to specify a date in the form specified by the current locale.

By default, this property is enabled.

The date edit is simpler in appearance than PySide.QtGui.QDateEdit , but allows the user to navigate between fields using the left and right cursor keys, increment and decrement individual fields using the up and down cursor keys, and enter values directly using the number keys.

PySide.QtGui.QCalendarWidget.setDateRange(min, max)
Parameters:

Defines a date range by setting the PySide.QtGui.QCalendarWidget.minimumDate() and PySide.QtGui.QCalendarWidget.maximumDate() properties.

The date range restricts the user selection, i.e. the user can only select dates within the specified date range. Note that

calendar.setDateRange(min, max)

is analogous to

calendar.setMinimumDate(min)
calendar.setMaximumDate(max)

If either the min or max parameters are not valid PySide.QtCore.QDate objects, this function does nothing.

PySide.QtGui.QCalendarWidget.setDateTextFormat(date, format)
Parameters:

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

If date is null, all date formats are cleared.

PySide.QtGui.QCalendarWidget.setFirstDayOfWeek(dayOfWeek)
Parameters:dayOfWeekPySide.QtCore.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

PySide.QtGui.QCalendarWidget.setGridVisible(show)
Parameters:showPySide.QtCore.bool

This property holds whether the table grid is displayed..

../../_images/qcalendarwidget-grid.png
calendar.setGridVisible(True)

The default value is false.

PySide.QtGui.QCalendarWidget.setHeaderTextFormat(format)
Parameters:formatPySide.QtGui.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.

PySide.QtGui.QCalendarWidget.setHorizontalHeaderFormat(format)
Parameters:formatPySide.QtGui.QCalendarWidget.HorizontalHeaderFormat

This property holds the format of the horizontal header..

The default value is QCalendarWidget.ShortDayNames .

PySide.QtGui.QCalendarWidget.setMaximumDate(date)
Parameters:datePySide.QtCore.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.

../../_images/qcalendarwidget-maximum.png
calendar.setGridVisible(True)
calendar.setMaximumDate(QDate(2006, 7, 3))

By default, the maximum date is the last day the PySide.QtCore.QDate class can handle.

When setting a maximum date, the PySide.QtGui.QCalendarWidget.minimumDate() and PySide.QtGui.QCalendarWidget.selectedDate() properties are adjusted if the selection range becomes invalid. If the provided date is not a valid PySide.QtCore.QDate object, the PySide.QtGui.QCalendarWidget.setMaximumDate() function does nothing.

PySide.QtGui.QCalendarWidget.setMinimumDate(date)
Parameters:datePySide.QtCore.QDate

This property holds the minimum date of the currently specified date range..

The user will not be able to select a date that is before the currently set minimum date.

../../_images/qcalendarwidget-minimum.png
calendar.setGridVisible(True)
calendar.setMinimumDate(QDate(2006, 6, 19))

By default, the minimum date is the earliest date that the PySide.QtCore.QDate class can handle.

When setting a minimum date, the PySide.QtGui.QCalendarWidget.maximumDate() and PySide.QtGui.QCalendarWidget.selectedDate() properties are adjusted if the selection range becomes invalid. If the provided date is not a valid PySide.QtCore.QDate object, the PySide.QtGui.QCalendarWidget.setMinimumDate() function does nothing.

PySide.QtGui.QCalendarWidget.setNavigationBarVisible(visible)
Parameters:visiblePySide.QtCore.bool

This property holds whether the navigation bar is shown or not.

When this property is true (the default), the next month, previous month, month selection, year selection controls are shown on top.

When the property is set to false, these controls are hidden.

PySide.QtGui.QCalendarWidget.setSelectedDate(date)
Parameters:datePySide.QtCore.QDate

This property holds the currently selected date..

The selected date must be within the date range specified by the PySide.QtGui.QCalendarWidget.minimumDate() and PySide.QtGui.QCalendarWidget.maximumDate() properties. By default, the selected date is the current date.

PySide.QtGui.QCalendarWidget.setSelectionMode(mode)
Parameters:modePySide.QtGui.QCalendarWidget.SelectionMode

This property holds the type of selection the user can make in the calendar.

When this property is set to SingleSelection , the user can select a date within the minimum and maximum allowed dates, using either the mouse or the keyboard.

When the property is set to NoSelection , the user will be unable to select dates, but they can still be selected programmatically. Note that the date that is selected when the property is set to NoSelection will still be the selected date of the calendar.

The default value is SingleSelection .

PySide.QtGui.QCalendarWidget.setVerticalHeaderFormat(format)
Parameters:formatPySide.QtGui.QCalendarWidget.VerticalHeaderFormat

This property holds the format of the vertical header..

The default value is QCalendarWidget::ISOWeekNumber.

PySide.QtGui.QCalendarWidget.setWeekdayTextFormat(dayOfWeek, format)
Parameters:
PySide.QtGui.QCalendarWidget.showNextMonth()

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

PySide.QtGui.QCalendarWidget.showNextYear()

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

PySide.QtGui.QCalendarWidget.showPreviousMonth()

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

PySide.QtGui.QCalendarWidget.showPreviousYear()

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

PySide.QtGui.QCalendarWidget.showSelectedDate()

Shows the month of the selected date.

PySide.QtGui.QCalendarWidget.showToday()

Shows the month of the today’s date.

PySide.QtGui.QCalendarWidget.updateCell(date)
Parameters:datePySide.QtCore.QDate

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

PySide.QtGui.QCalendarWidget.updateCells()

Updates all visible cells unless updates are disabled.

PySide.QtGui.QCalendarWidget.verticalHeaderFormat()
Return type:PySide.QtGui.QCalendarWidget.VerticalHeaderFormat

This property holds the format of the vertical header..

The default value is QCalendarWidget::ISOWeekNumber.

PySide.QtGui.QCalendarWidget.weekdayTextFormat(dayOfWeek)
Parameters:dayOfWeekPySide.QtCore.Qt.DayOfWeek
Return type:PySide.QtGui.QTextCharFormat
PySide.QtGui.QCalendarWidget.yearShown()
Return type:PySide.QtCore.int

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