QtBase
v6.3.1
|
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date. More...
#include <qcalendarwidget.h>
Public Types | |
enum | HorizontalHeaderFormat { NoHorizontalHeader , SingleLetterDayNames , ShortDayNames , LongDayNames } |
enum | VerticalHeaderFormat { NoVerticalHeader , ISOWeekNumbers } |
enum | SelectionMode { NoSelection , SingleSelection } |
Public Types inherited from QWidget | |
enum | RenderFlag { DrawWindowBackground = 0x1 , DrawChildren = 0x2 , IgnoreMask = 0x4 } |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric { PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM , PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY , PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled } |
Public Slots | |
void | setSelectedDate (QDate date) |
void | setDateRange (QDate min, QDate max) |
void | setCurrentPage (int year, int month) |
void | setGridVisible (bool show) |
void | setNavigationBarVisible (bool visible) |
void | showNextMonth () |
void | showPreviousMonth () |
void | showNextYear () |
void | showPreviousYear () |
void | showSelectedDate () |
void | showToday () |
Public Slots inherited from QWidget | |
void | setEnabled (bool) |
void | setDisabled (bool) |
void | setWindowModified (bool) |
void | setWindowTitle (const QString &) |
void | setStyleSheet (const QString &styleSheet) |
void | setFocus () |
void | update () |
void | repaint () |
virtual void | setVisible (bool visible) |
void | setHidden (bool hidden) |
void | show () |
void | hide () |
void | showMinimized () |
void | showMaximized () |
void | showFullScreen () |
void | showNormal () |
bool | close () |
void | raise () |
void | lower () |
Public Slots inherited from QObject | |
void | deleteLater () |
Signals | |
void | selectionChanged () |
void | clicked (QDate date) |
void | activated (QDate date) |
void | currentPageChanged (int year, int month) |
Signals inherited from QWidget | |
void | windowTitleChanged (const QString &title) |
void | windowIconChanged (const QIcon &icon) |
void | windowIconTextChanged (const QString &iconText) |
void | customContextMenuRequested (const QPoint &pos) |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Properties | |
QDate | selectedDate |
the currently selected date. More... | |
QDate | minimumDate |
the minimum date of the currently specified date range. More... | |
QDate | maximumDate |
the maximum date of the currently specified date range. More... | |
Qt::DayOfWeek | firstDayOfWeek |
a value identifying the day displayed in the first column. More... | |
bool | gridVisible |
whether the table grid is displayed. More... | |
SelectionMode | selectionMode |
the type of selection the user can make in the calendar More... | |
HorizontalHeaderFormat | horizontalHeaderFormat |
the format of the horizontal header. More... | |
VerticalHeaderFormat | verticalHeaderFormat |
the format of the vertical header. More... | |
bool | navigationBarVisible |
whether the navigation bar is shown or not More... | |
bool | dateEditEnabled |
whether the date edit popup is enabled More... | |
int | dateEditAcceptDelay |
the time an inactive date edit is shown before its contents are accepted More... | |
Properties inherited from QWidget | |
bool | modal |
whether the widget is a modal widget More... | |
Qt::WindowModality | windowModality |
which windows are blocked by the modal widget More... | |
bool | enabled |
whether the widget is enabled More... | |
QRect | geometry |
the geometry of the widget relative to its parent and excluding the window frame More... | |
QRect | frameGeometry |
geometry of the widget relative to its parent including any window frame More... | |
QRect | normalGeometry |
the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget More... | |
int | x |
the x coordinate of the widget relative to its parent including any window frame More... | |
int | y |
the y coordinate of the widget relative to its parent and including any window frame More... | |
QPoint | pos |
the position of the widget within its parent widget More... | |
QSize | frameSize |
the size of the widget including any window frame More... | |
QSize | size |
the size of the widget excluding any window frame More... | |
int | width |
the width of the widget excluding any window frame More... | |
int | height |
the height of the widget excluding any window frame More... | |
QRect | rect |
the internal geometry of the widget excluding any window frame More... | |
QRect | childrenRect |
the bounding rectangle of the widget's children More... | |
QRegion | childrenRegion |
the combined region occupied by the widget's children More... | |
QSizePolicy | sizePolicy |
the default layout behavior of the widget More... | |
QSize | minimumSize |
the widget's minimum size More... | |
QSize | maximumSize |
the widget's maximum size in pixels More... | |
int | minimumWidth |
the widget's minimum width in pixels More... | |
int | minimumHeight |
the widget's minimum height in pixels More... | |
int | maximumWidth |
the widget's maximum width in pixels More... | |
int | maximumHeight |
the widget's maximum height in pixels More... | |
QSize | sizeIncrement |
the size increment of the widget More... | |
QSize | baseSize |
the base size of the widget More... | |
QPalette | palette |
the widget's palette More... | |
QFont | font |
the font currently set for the widget More... | |
QCursor | cursor |
the cursor shape for this widget More... | |
bool | mouseTracking |
whether mouse tracking is enabled for the widget More... | |
bool | tabletTracking |
whether tablet tracking is enabled for the widget More... | |
bool | isActiveWindow |
whether this widget's window is the active window More... | |
Qt::FocusPolicy | focusPolicy |
the way the widget accepts keyboard focus More... | |
bool | focus |
whether this widget (or its focus proxy) has the keyboard input focus More... | |
Qt::ContextMenuPolicy | contextMenuPolicy |
how the widget shows a context menu More... | |
bool | updatesEnabled |
whether updates are enabled More... | |
bool | visible |
whether the widget is visible More... | |
bool | minimized |
whether this widget is minimized (iconified) More... | |
bool | maximized |
whether this widget is maximized More... | |
bool | fullScreen |
whether the widget is shown in full screen mode More... | |
QSize | sizeHint |
the recommended size for the widget More... | |
QSize | minimumSizeHint |
the recommended minimum size for the widget More... | |
bool | acceptDrops |
whether drop events are enabled for this widget More... | |
QString | windowTitle |
the window title (caption) More... | |
QIcon | windowIcon |
the widget's icon More... | |
QString | windowIconText |
the text to be displayed on the icon of a minimized window More... | |
double | windowOpacity |
The level of opacity for the window. More... | |
bool | windowModified |
whether the document shown in the window has unsaved changes More... | |
QString | accessibleName |
the widget's name as seen by assistive technologies More... | |
QString | accessibleDescription |
the widget's description as seen by assistive technologies More... | |
Qt::LayoutDirection | layoutDirection |
the layout direction for this widget. More... | |
bool | autoFillBackground |
whether the widget background is filled automatically More... | |
QString | styleSheet |
the widget's style sheet More... | |
QLocale | locale |
the widget's locale More... | |
QString | windowFilePath |
the file path associated with a widget More... | |
Qt::InputMethodHints | inputMethodHints |
What input method specific hints the widget has. More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date.
\inmodule QtWidgets
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 \l 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 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 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:
\table \row
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.
Definition at line 55 of file qcalendarwidget.h.
This enum type defines the various formats the horizontal header can display.
\value SingleLetterDayNames The header displays a single letter abbreviation for day names (e.g. M for Monday). \value ShortDayNames The header displays a short abbreviation for day names (e.g. Mon for Monday). \value LongDayNames The header displays complete day names (e.g. Monday). \value NoHorizontalHeader The header is hidden.
Enumerator | |
---|---|
NoHorizontalHeader | |
SingleLetterDayNames | |
ShortDayNames | |
LongDayNames |
Definition at line 74 of file qcalendarwidget.h.
This enum describes the types of selection offered to the user for selecting dates in the calendar.
\value NoSelection Dates cannot be selected. \value SingleSelection Single dates can be selected.
Enumerator | |
---|---|
NoSelection | |
SingleSelection |
Definition at line 88 of file qcalendarwidget.h.
This enum type defines the various formats the vertical header can display.
\value ISOWeekNumbers The header displays ISO week numbers as described by \l QDate::weekNumber(). \value NoVerticalHeader The header is hidden.
Enumerator | |
---|---|
NoVerticalHeader | |
ISOWeekNumbers |
Definition at line 82 of file qcalendarwidget.h.
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.
Definition at line 2122 of file qcalendarwidget.cpp.
QCalendarWidget::~QCalendarWidget | ( | ) |
Destroys the calendar widget.
Definition at line 2190 of file qcalendarwidget.cpp.
This signal is emitted whenever the user presses the Return or Enter key or double-clicks a date in the calendar widget.
QCalendar QCalendarWidget::calendar | ( | ) | const |
Definition at line 2743 of file qcalendarwidget.cpp.
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.
|
signal |
This signal is emitted when the currently shown month is changed. The new year and month are passed as parameters.
int QCalendarWidget::dateEditAcceptDelay | ( | ) | const |
Definition at line 2957 of file qcalendarwidget.cpp.
QMap< QDate, QTextCharFormat > QCalendarWidget::dateTextFormat | ( | ) | const |
Returns a QMap from QDate to QTextCharFormat showing all dates that use a special format that alters their rendering.
Definition at line 2878 of file qcalendarwidget.cpp.
QTextCharFormat QCalendarWidget::dateTextFormat | ( | QDate | date | ) | const |
Returns a QTextCharFormat for date. The char format can be be empty if the date is not renderd specially.
Definition at line 2888 of file qcalendarwidget.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 3086 of file qcalendarwidget.cpp.
\reimp
Reimplemented from QObject.
Definition at line 3120 of file qcalendarwidget.cpp.
Qt::DayOfWeek QCalendarWidget::firstDayOfWeek | ( | ) | const |
Definition at line 2816 of file qcalendarwidget.cpp.
QTextCharFormat QCalendarWidget::headerTextFormat | ( | ) | const |
Returns the text char format for rendering the header.
Definition at line 2825 of file qcalendarwidget.cpp.
QCalendarWidget::HorizontalHeaderFormat QCalendarWidget::horizontalHeaderFormat | ( | ) | const |
Definition at line 2674 of file qcalendarwidget.cpp.
bool QCalendarWidget::isDateEditEnabled | ( | ) | const |
bool QCalendarWidget::isGridVisible | ( | ) | const |
Definition at line 2737 of file qcalendarwidget.cpp.
bool QCalendarWidget::isNavigationBarVisible | ( | ) | const |
Definition at line 3067 of file qcalendarwidget.cpp.
\reimp
Reimplemented from QWidget.
Definition at line 3174 of file qcalendarwidget.cpp.
QDate QCalendarWidget::maximumDate | ( | ) | const |
Definition at line 2576 of file qcalendarwidget.cpp.
QDate QCalendarWidget::minimumDate | ( | ) | const |
Definition at line 2525 of file qcalendarwidget.cpp.
|
overridevirtual |
\reimp
Reimplemented from QWidget.
Definition at line 2205 of file qcalendarwidget.cpp.
int QCalendarWidget::monthShown | ( | ) | const |
Returns the currently displayed month. Months are numbered from 1 to 12.
Definition at line 2359 of file qcalendarwidget.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 3148 of file qcalendarwidget.cpp.
|
protectedvirtual |
Paints the cell specified by the given date, using the given painter and rect.
Definition at line 2299 of file qcalendarwidget.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 3158 of file qcalendarwidget.cpp.
QDate QCalendarWidget::selectedDate | ( | ) | const |
Definition at line 2316 of file qcalendarwidget.cpp.
|
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().
QCalendarWidget::SelectionMode QCalendarWidget::selectionMode | ( | ) | const |
Definition at line 2784 of file qcalendarwidget.cpp.
Definition at line 2749 of file qcalendarwidget.cpp.
|
slot |
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.
Definition at line 2377 of file qcalendarwidget.cpp.
void QCalendarWidget::setDateEditAcceptDelay | ( | int | delay | ) |
Definition at line 2963 of file qcalendarwidget.cpp.
void QCalendarWidget::setDateEditEnabled | ( | bool | enable | ) |
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
is analogous to
If either the min or max parameters are not valid QDate objects, this function does nothing.
Definition at line 2620 of file qcalendarwidget.cpp.
void QCalendarWidget::setDateTextFormat | ( | QDate | date, |
const QTextCharFormat & | format | ||
) |
Sets the format used to render the given date to that specified by format.
If date is null, all date formats are cleared.
Definition at line 2899 of file qcalendarwidget.cpp.
void QCalendarWidget::setFirstDayOfWeek | ( | Qt::DayOfWeek | dayOfWeek | ) |
|
slot |
void QCalendarWidget::setHeaderTextFormat | ( | const QTextCharFormat & | format | ) |
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.
Definition at line 2838 of file qcalendarwidget.cpp.
void QCalendarWidget::setHorizontalHeaderFormat | ( | QCalendarWidget::HorizontalHeaderFormat | format | ) |
Definition at line 2662 of file qcalendarwidget.cpp.
Definition at line 2582 of file qcalendarwidget.cpp.
Definition at line 2531 of file qcalendarwidget.cpp.
|
slot |
Definition at line 2322 of file qcalendarwidget.cpp.
void QCalendarWidget::setSelectionMode | ( | SelectionMode | mode | ) |
void QCalendarWidget::setVerticalHeaderFormat | ( | QCalendarWidget::VerticalHeaderFormat | format | ) |
void QCalendarWidget::setWeekdayTextFormat | ( | Qt::DayOfWeek | dayOfWeek, |
const QTextCharFormat & | format | ||
) |
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.
Definition at line 2865 of file qcalendarwidget.cpp.
|
slot |
Shows the next month relative to the currently displayed month. Note that the selected date is not changed.
Definition at line 2405 of file qcalendarwidget.cpp.
|
slot |
Shows the currently displayed month in the next year relative to the currently displayed year. Note that the selected date is not changed.
Definition at line 2449 of file qcalendarwidget.cpp.
|
slot |
Shows the previous month relative to the currently displayed month. Note that the selected date is not changed.
Definition at line 2426 of file qcalendarwidget.cpp.
|
slot |
Shows the currently displayed month in the previous year relative to the currently displayed year. Note that the selected date is not changed.
Definition at line 2465 of file qcalendarwidget.cpp.
|
slot |
Shows the month of the selected date.
Definition at line 2478 of file qcalendarwidget.cpp.
|
slot |
Shows the month of the today's date.
Definition at line 2491 of file qcalendarwidget.cpp.
|
overridevirtual |
\reimp
Reimplemented from QWidget.
Definition at line 2197 of file qcalendarwidget.cpp.
Updates the cell specified by the given date unless updates are disabled or the cell is hidden.
Definition at line 2977 of file qcalendarwidget.cpp.
|
protected |
Updates all visible cells unless updates are disabled.
Definition at line 3007 of file qcalendarwidget.cpp.
QCalendarWidget::VerticalHeaderFormat QCalendarWidget::verticalHeaderFormat | ( | ) | const |
Definition at line 2699 of file qcalendarwidget.cpp.
QTextCharFormat QCalendarWidget::weekdayTextFormat | ( | Qt::DayOfWeek | dayOfWeek | ) | const |
Returns the text char format for rendering of day in the week dayOfWeek.
Definition at line 2852 of file qcalendarwidget.cpp.
int QCalendarWidget::yearShown | ( | ) | const |
Returns the year of the currently displayed month. Months are numbered from 1 to 12.
Definition at line 2346 of file qcalendarwidget.cpp.
|
readwrite |
the time an inactive date edit is shown before its contents are accepted
If the calendar widget's \l{dateEditEnabled}{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).
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
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.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
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.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
whether the table grid is displayed.
\table \row
The default value is false.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
the format of the horizontal header.
The default value is QCalendarWidget::ShortDayNames.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
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.
\table \row
By default, the maximum date is the last day the QDate class can handle.
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.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
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.
\table \row
By default, the minimum date is the earliest date that the QDate class can handle.
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.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
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.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
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.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
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.
Definition at line 191 of file qcalendarwidget.h.
|
readwrite |
the format of the vertical header.
The default value is QCalendarWidget::ISOWeekNumber.
Definition at line 191 of file qcalendarwidget.h.