QCalendarWidget¶
The
QCalendarWidget
class provides a monthly based calendar widget allowing the user to select a date. More…
Synopsis¶
Functions¶
def
calendar
()def
dateEditAcceptDelay
()def
dateTextFormat
()def
dateTextFormat
(date)def
firstDayOfWeek
()def
headerTextFormat
()def
horizontalHeaderFormat
()def
isDateEditEnabled
()def
isGridVisible
()def
isNavigationBarVisible
()def
maximumDate
()def
minimumDate
()def
monthShown
()def
selectedDate
()def
selectionMode
()def
setCalendar
(calendar)def
setDateEditAcceptDelay
(delay)def
setDateEditEnabled
(enable)def
setDateTextFormat
(date, format)def
setFirstDayOfWeek
(dayOfWeek)def
setHeaderTextFormat
(format)def
setHorizontalHeaderFormat
(format)def
setMaximumDate
(date)def
setMinimumDate
(date)def
setSelectionMode
(mode)def
setVerticalHeaderFormat
(format)def
setWeekdayTextFormat
(dayOfWeek, format)def
updateCell
(date)def
updateCells
()def
verticalHeaderFormat
()def
weekdayTextFormat
(dayOfWeek)def
yearShown
()
Virtual functions¶
def
paintCell
(painter, rect, date)
Slots¶
def
setCurrentPage
(year, month)def
setDateRange
(min, max)def
setGridVisible
(show)def
setNavigationBarVisible
(visible)def
setSelectedDate
(date)def
showNextMonth
()def
showNextYear
()def
showPreviousMonth
()def
showPreviousYear
()def
showSelectedDate
()def
showToday
()
Signals¶
def
activated
(date)def
clicked
(date)def
currentPageChanged
(year, month)def
selectionChanged
()
Detailed Description¶
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 theminimumDate
andmaximumDate
properties. Alternatively, both properties can be set in one go using thesetDateRange()
convenience slot. Set theselectionMode
property toNoSelection
to prohibit the user from selecting at all. Note that a date also can be selected programmatically using thesetSelectedDate()
slot.The currently displayed month and year can be retrieved using the
monthShown()
andyearShown()
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 the first day of the week for the calendar’s locale.
The notation of the days can be altered to a single letter abbreviations (“M” for “Monday”) by setting the
horizontalHeaderFormat
property toSingleLetterDayNames
. Setting the same property toLongDayNames
makes the header display the complete day names. The week numbers can be removed by setting theverticalHeaderFormat
property toNoVerticalHeader
. The calendar grid can be turned on by setting thegridVisible
property to true using thesetGridVisible()
function:
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()
andcurrentPageChanged()
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
QTextCharFormat
- class PySide2.QtWidgets.QCalendarWidget([parent=None])¶
- param parent:
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
- PySide2.QtWidgets.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
horizontalHeaderFormat()
VerticalHeaderFormat
- PySide2.QtWidgets.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
weekNumber()
.QCalendarWidget.NoVerticalHeader
The header is hidden.
See also
verticalHeaderFormat()
HorizontalHeaderFormat
- PySide2.QtWidgets.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.
See also
- PySide2.QtWidgets.QCalendarWidget.activated(date)¶
- Parameters:
date –
PySide2.QtCore.QDate
- PySide2.QtWidgets.QCalendarWidget.calendar()¶
- Return type:
- PySide2.QtWidgets.QCalendarWidget.clicked(date)¶
- Parameters:
date –
PySide2.QtCore.QDate
- PySide2.QtWidgets.QCalendarWidget.currentPageChanged(year, month)¶
- Parameters:
year – int
month – int
- PySide2.QtWidgets.QCalendarWidget.dateEditAcceptDelay()¶
- Return type:
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 milliseconds) 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).
- PySide2.QtWidgets.QCalendarWidget.dateTextFormat()¶
- Return type:
Returns a
QMap
fromQDate
toQTextCharFormat
showing all dates that use a special format that alters their rendering.See also
- PySide2.QtWidgets.QCalendarWidget.dateTextFormat(date)
- Parameters:
date –
PySide2.QtCore.QDate
- Return type:
Returns a
QTextCharFormat
fordate
. The char format can be be empty if the date is not renderd specially.
- PySide2.QtWidgets.QCalendarWidget.firstDayOfWeek()¶
- Return type:
This property holds a value identifying the day displayed in the first column..
By default, the day displayed in the first column is the first day of the week for the calendar’s locale.
- PySide2.QtWidgets.QCalendarWidget.headerTextFormat()¶
- Return type:
Returns the text char format for rendering the header.
See also
- PySide2.QtWidgets.QCalendarWidget.horizontalHeaderFormat()¶
- Return type:
This property holds the format of the horizontal header..
The default value is
ShortDayNames
.
- PySide2.QtWidgets.QCalendarWidget.isDateEditEnabled()¶
- Return type:
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
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.See also
- PySide2.QtWidgets.QCalendarWidget.isGridVisible()¶
- Return type:
bool
This property holds whether the table grid is displayed..
calendar.setGridVisible(True)
The default value is false.
- Return type:
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.
- PySide2.QtWidgets.QCalendarWidget.maximumDate()¶
- Return type:
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.
calendar.setGridVisible(True) calendar.setMaximumDate(QDate(2006, 7, 3))
By default, the maximum date is the last day the
QDate
class can handle.When setting a maximum date, the
minimumDate
andselectedDate
properties are adjusted if the selection range becomes invalid. If the provided date is not a validQDate
object, the function does nothing.See also
- PySide2.QtWidgets.QCalendarWidget.minimumDate()¶
- Return type:
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.
calendar.setGridVisible(True) calendar.setMinimumDate(QDate(2006, 6, 19))
By default, the minimum date is the earliest date that the
QDate
class can handle.When setting a minimum date, the
maximumDate
andselectedDate
properties are adjusted if the selection range becomes invalid. If the provided date is not a validQDate
object, the function does nothing.See also
- PySide2.QtWidgets.QCalendarWidget.monthShown()¶
- Return type:
int
Returns the currently displayed month. Months are numbered from 1 to 12.
See also
- PySide2.QtWidgets.QCalendarWidget.paintCell(painter, rect, date)¶
- Parameters:
painter –
PySide2.QtGui.QPainter
rect –
PySide2.QtCore.QRect
date –
PySide2.QtCore.QDate
Paints the cell specified by the given
date
, using the givenpainter
andrect
.
- PySide2.QtWidgets.QCalendarWidget.selectedDate()¶
- Return type:
This property holds the currently selected date..
The selected date must be within the date range specified by the
minimumDate
andmaximumDate
properties. By default, the selected date is the current date.See also
- PySide2.QtWidgets.QCalendarWidget.selectionChanged()¶
- PySide2.QtWidgets.QCalendarWidget.selectionMode()¶
- Return type:
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 toNoSelection
will still be the selected date of the calendar.The default value is
SingleSelection
.
- PySide2.QtWidgets.QCalendarWidget.setCalendar(calendar)¶
- Parameters:
calendar –
PySide2.QtCore.QCalendar
- PySide2.QtWidgets.QCalendarWidget.setCurrentPage(year, month)¶
- Parameters:
year – int
month – int
Displays the given
month
of the givenyear
without changing the selected date. Use thesetSelectedDate()
function to alter the selected date.The currently displayed month and year can be retrieved using the
monthShown()
andyearShown()
functions respectively.
- PySide2.QtWidgets.QCalendarWidget.setDateEditAcceptDelay(delay)¶
- Parameters:
delay – 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 milliseconds) 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).
- PySide2.QtWidgets.QCalendarWidget.setDateEditEnabled(enable)¶
- Parameters:
enable – 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
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.See also
- PySide2.QtWidgets.QCalendarWidget.setDateRange(min, max)¶
- Parameters:
min –
PySide2.QtCore.QDate
max –
PySide2.QtCore.QDate
Defines a date range by setting the
minimumDate
andmaximumDate
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
ormax
parameters are not validQDate
objects, this function does nothing.See also
- PySide2.QtWidgets.QCalendarWidget.setDateTextFormat(date, format)¶
- Parameters:
date –
PySide2.QtCore.QDate
format –
PySide2.QtGui.QTextCharFormat
Sets the format used to render the given
date
to that specified byformat
.If
date
is null, all date formats are cleared.See also
- PySide2.QtWidgets.QCalendarWidget.setFirstDayOfWeek(dayOfWeek)¶
- Parameters:
dayOfWeek –
DayOfWeek
This property holds a value identifying the day displayed in the first column..
By default, the day displayed in the first column is the first day of the week for the calendar’s locale.
- PySide2.QtWidgets.QCalendarWidget.setGridVisible(show)¶
- Parameters:
show – bool
This property holds whether the table grid is displayed..
calendar.setGridVisible(True)
The default value is false.
- PySide2.QtWidgets.QCalendarWidget.setHeaderTextFormat(format)¶
- Parameters:
format –
PySide2.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.See also
- PySide2.QtWidgets.QCalendarWidget.setHorizontalHeaderFormat(format)¶
- Parameters:
format –
HorizontalHeaderFormat
This property holds the format of the horizontal header..
The default value is
ShortDayNames
.
- PySide2.QtWidgets.QCalendarWidget.setMaximumDate(date)¶
- Parameters:
date –
PySide2.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.
calendar.setGridVisible(True) calendar.setMaximumDate(QDate(2006, 7, 3))
By default, the maximum date is the last day the
QDate
class can handle.When setting a maximum date, the
minimumDate
andselectedDate
properties are adjusted if the selection range becomes invalid. If the provided date is not a validQDate
object, the function does nothing.See also
- PySide2.QtWidgets.QCalendarWidget.setMinimumDate(date)¶
- Parameters:
date –
PySide2.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.
calendar.setGridVisible(True) calendar.setMinimumDate(QDate(2006, 6, 19))
By default, the minimum date is the earliest date that the
QDate
class can handle.When setting a minimum date, the
maximumDate
andselectedDate
properties are adjusted if the selection range becomes invalid. If the provided date is not a validQDate
object, the function does nothing.See also
- Parameters:
visible – 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.
- PySide2.QtWidgets.QCalendarWidget.setSelectedDate(date)¶
- Parameters:
date –
PySide2.QtCore.QDate
This property holds the currently selected date..
The selected date must be within the date range specified by the
minimumDate
andmaximumDate
properties. By default, the selected date is the current date.See also
- PySide2.QtWidgets.QCalendarWidget.setSelectionMode(mode)¶
- Parameters:
mode –
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 toNoSelection
will still be the selected date of the calendar.The default value is
SingleSelection
.
- PySide2.QtWidgets.QCalendarWidget.setVerticalHeaderFormat(format)¶
- Parameters:
format –
VerticalHeaderFormat
This property holds the format of the vertical header..
The default value is QCalendarWidget::ISOWeekNumber.
- PySide2.QtWidgets.QCalendarWidget.setWeekdayTextFormat(dayOfWeek, format)¶
- Parameters:
dayOfWeek –
DayOfWeek
format –
PySide2.QtGui.QTextCharFormat
Sets the text char format for rendering of day in the week
dayOfWeek
toformat
. 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
- PySide2.QtWidgets.QCalendarWidget.showNextMonth()¶
Shows the next month relative to the currently displayed month. Note that the selected date is not changed.
- PySide2.QtWidgets.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.
- PySide2.QtWidgets.QCalendarWidget.showPreviousMonth()¶
Shows the previous month relative to the currently displayed month. Note that the selected date is not changed.
- PySide2.QtWidgets.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.
- PySide2.QtWidgets.QCalendarWidget.showSelectedDate()¶
Shows the month of the selected date.
See also
- PySide2.QtWidgets.QCalendarWidget.showToday()¶
Shows the month of the today’s date.
See also
- PySide2.QtWidgets.QCalendarWidget.updateCell(date)¶
- Parameters:
date –
PySide2.QtCore.QDate
Updates the cell specified by the given
date
unless updates are disabled or the cell is hidden.See also
- PySide2.QtWidgets.QCalendarWidget.updateCells()¶
Updates all visible cells unless updates are disabled.
See also
- PySide2.QtWidgets.QCalendarWidget.verticalHeaderFormat()¶
- Return type:
This property holds the format of the vertical header..
The default value is QCalendarWidget::ISOWeekNumber.
- PySide2.QtWidgets.QCalendarWidget.weekdayTextFormat(dayOfWeek)¶
- Parameters:
dayOfWeek –
DayOfWeek
- Return type:
Returns the text char format for rendering of day in the week
dayOfWeek
.See also
- PySide2.QtWidgets.QCalendarWidget.yearShown()¶
- Return type:
int
Returns the year of the currently displayed month. Months are numbered from 1 to 12.
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.