CopperSpice API  1.9.2
QCalendarWidget Class Reference

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

Inheritance diagram for QCalendarWidget:
QWidget QObject QPaintDevice

Public Types

enum  HorizontalHeaderFormat
 
enum  SelectionMode
 
enum  VerticalHeaderFormat
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Public Signals

void activated (const QDate &date)
 
void clicked (const QDate &date)
 
void currentPageChanged (int year, int month)
 
void selectionChanged ()
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void setCurrentPage (int year, int month)
 
void setDateRange (const QDate &min, const QDate &max)
 
void setGridVisible (bool show)
 
void setNavigationBarVisible (bool visible)
 
void setSelectedDate (const QDate &date)
 
void showNextMonth ()
 
void showNextYear ()
 
void showPreviousMonth ()
 
void showPreviousYear ()
 
void showSelectedDate ()
 
void showToday ()
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QCalendarWidget (QWidget *parent=nullptr)
 
 ~QCalendarWidget ()
 
int dateEditAcceptDelay () const
 
QMap< QDate, QTextCharFormatdateTextFormat () const
 
QTextCharFormat dateTextFormat (const QDate &date) const
 
Qt::DayOfWeek firstDayOfWeek () const
 
QTextCharFormat headerTextFormat () const
 
HorizontalHeaderFormat horizontalHeaderFormat () const
 
bool isDateEditEnabled () const
 
bool isGridVisible () const
 
bool isNavigationBarVisible () const
 
QDate maximumDate () const
 
QDate minimumDate () const
 
QSize minimumSizeHint () const override
 
int monthShown () const
 
QDate selectedDate () const
 
SelectionMode selectionMode () const
 
void setDateEditAcceptDelay (int delay)
 
void setDateEditEnabled (bool enable)
 
void setDateTextFormat (const QDate &date, const QTextCharFormat &format)
 
void setFirstDayOfWeek (Qt::DayOfWeek dayOfWeek)
 
void setHeaderTextFormat (const QTextCharFormat &format)
 
void setHorizontalHeaderFormat (HorizontalHeaderFormat format)
 
void setMaximumDate (const QDate &date)
 
void setMinimumDate (const QDate &date)
 
void setSelectionMode (SelectionMode mode)
 
void setVerticalHeaderFormat (VerticalHeaderFormat format)
 
void setWeekdayTextFormat (Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format)
 
QSize sizeHint () const override
 
VerticalHeaderFormat verticalHeaderFormat () const
 
QTextCharFormat weekdayTextFormat (Qt::DayOfWeek dayOfWeek) const
 
int yearShown () const
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int width) const
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

bool event (QEvent *event) override
 
bool eventFilter (QObject *watched, QEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
virtual void paintCell (QPainter *painter, const QRect &rect, const QDate &date) const
 
void resizeEvent (QResizeEvent *event) override
 
void updateCell (const QDate &date)
 
void updateCells ()
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void changeEvent (QEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
virtual void contextMenuEvent (QContextMenuEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void dragEnterEvent (QDragEnterEvent *event)
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event)
 
virtual void dropEvent (QDropEvent *event)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
virtual void focusInEvent (QFocusEvent *event)
 
bool focusNextChild ()
 
virtual bool focusNextPrevChild (bool next)
 
virtual void focusOutEvent (QFocusEvent *event)
 
bool focusPreviousChild ()
 
virtual void hideEvent (QHideEvent *event)
 
void initPainter (QPainter *painter) const override
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void mouseMoveEvent (QMouseEvent *event)
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void paintEvent (QPaintEvent *event)
 
virtual void showEvent (QShowEvent *event)
 
virtual void tabletEvent (QTabletEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 dateEditAcceptDelay
 
 dateEditEnabled
 
 firstDayOfWeek
 
 gridVisible
 
 horizontalHeaderFormat
 
 maximumDate
 
 minimumDate
 
 navigationBarVisible
 
 selectedDate
 
 selectionMode
 
 verticalHeaderFormat
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 
- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QCalendarWidget class provides a monthly calendar widget allowing the user to select a date. The widget is initialized with the current month and year. The QCalendarWidget provides several public slots to change the current year and month.

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

Date Syntax

By default a 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() method.

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

The day in the first column can be altered using the setFirstDayOfWeek() method.

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. The foreground, background and font properties are used to determine the rendering of individual cells in the widget.

See also
QDate, QDateEdit, QTextCharFormat

Member Enumeration Documentation

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

ConstantValueDescription
QCalendarWidget::NoHorizontalHeader0 Header is hidden.
QCalendarWidget::SingleLetterDayNames1 Header displays a singleletter abbreviation for day names (e.g. M for Monday).
QCalendarWidget::ShortDayNames2 Header displays a short abbreviation for day names (e.g. Mon for Monday).
QCalendarWidget::LongDayNames3 Header displays complete day names (e.g. Monday).
See also
horizontalHeaderFormat(), VerticalHeaderFormat

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

ConstantValueDescription
QCalendarWidget::NoSelection0Dates can not be selected.
QCalendarWidget::SingleSelection1Single dates can be selected.
See also
selectionMode

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

ConstantValueDescription
QCalendarWidget::NoVerticalHeader0 Header is hidden.
QCalendarWidget::ISOWeekNumbers1 Header displays ISO week numbers as described by QDate::weekNumber().
See also
verticalHeaderFormat(), HorizontalHeaderFormat

Constructor & Destructor Documentation

QCalendarWidget::QCalendarWidget ( QWidget parent = nullptr)
explicit

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()
QCalendarWidget::~QCalendarWidget ( )

Destroys the calendar widget.

Method Documentation

void QCalendarWidget::activated ( const QDate date)
signal

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

void QCalendarWidget::clicked ( const QDate date)
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 QCalendarWidget::currentPageChanged ( int  year,
int  month 
)
signal

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

See also
setCurrentPage()
int QCalendarWidget::dateEditAcceptDelay ( ) const

Returns the value of the dateEditAcceptDelay property.

QMap< QDate, QTextCharFormat > QCalendarWidget::dateTextFormat ( ) const

Returns a QMap where the key is a QDate and the value is the corresponding QTextCharFormat. The map contains all of the dates which are rendered in the special format.

See also
setDateTextFormat()
QTextCharFormat QCalendarWidget::dateTextFormat ( const QDate date) const

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

bool QCalendarWidget::event ( QEvent event)
overrideprotected

Reimplemented from QWidget::event()

bool QCalendarWidget::eventFilter ( QObject watched,
QEvent event 
)
overrideprotected

Reimplemented from QWidget::eventFilter()

Qt::DayOfWeek QCalendarWidget::firstDayOfWeek ( ) const

Returns the value of the firstDayOfWeek property.

QTextCharFormat QCalendarWidget::headerTextFormat ( ) const

Returns the text char format for rendering the header.

See also
setHeaderTextFormat()
HorizontalHeaderFormat QCalendarWidget::horizontalHeaderFormat ( ) const

Returns the value of the horizontalHeaderFormat property.

bool QCalendarWidget::isDateEditEnabled ( ) const

Returns the value of the dateEditEnabled property.

bool QCalendarWidget::isGridVisible ( ) const

Returns the value of the gridVisible property.

bool QCalendarWidget::isNavigationBarVisible ( ) const

Returns the value of the navigationBarVisible property.

void QCalendarWidget::keyPressEvent ( QKeyEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::keyPressEvent()

QDate QCalendarWidget::maximumDate ( ) const

Returns the value of the maximumDate property.

QDate QCalendarWidget::minimumDate ( ) const

Returns the value of the minimumDate property.

QSize QCalendarWidget::minimumSizeHint ( ) const
overridevirtual

Reimplemented from QWidget::minimumSizeHint()

int QCalendarWidget::monthShown ( ) const

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

See also
yearShown(), setCurrentPage()
void QCalendarWidget::mousePressEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mousePressEvent()

void QCalendarWidget::paintCell ( QPainter painter,
const QRect rect,
const QDate date 
) const
protectedvirtual

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

void QCalendarWidget::resizeEvent ( QResizeEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::resizeEvent()

QDate QCalendarWidget::selectedDate ( ) const

Returns the value of the selectedDate property.

void QCalendarWidget::selectionChanged ( )
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()
SelectionMode QCalendarWidget::selectionMode ( ) const

Returns the value of the selectionMode property.

void QCalendarWidget::setCurrentPage ( int  year,
int  month 
)
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() methods respectively.

See also
yearShown(), monthShown(), showPreviousMonth(), showNextMonth(), showPreviousYear(), showNextYear()
void QCalendarWidget::setDateEditAcceptDelay ( int  delay)

Sets the value of the dateEditAcceptDelay property to delay.

void QCalendarWidget::setDateEditEnabled ( bool  enable)

Sets the value of the dateEditEnabled property to enable.

void QCalendarWidget::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.

The following two examples are equivalent. If either the min or max parameters are not valid QDate objects, this method does nothing.

// 1
QCalendarWidget *calendar;
calendar->setDateRange(min, max);
// 2
QCalendarWidget *calendar;
calendar->setMinimumDate(min);
calendar->setMaximumDate(max);
See also
setMinimumDate(), setMaximumDate()
void QCalendarWidget::setDateTextFormat ( const 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.

See also
dateTextFormat()
void QCalendarWidget::setFirstDayOfWeek ( Qt::DayOfWeek  dayOfWeek)

Sets the value of the firstDayOfWeek property dayOfWeek.

void QCalendarWidget::setGridVisible ( bool  show)
slot

Sets the value of the gridVisible property to show.

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.

See also
headerTextFormat()
void QCalendarWidget::setHorizontalHeaderFormat ( HorizontalHeaderFormat  format)

Sets the value of the horizontalHeaderFormat property to format.

void QCalendarWidget::setMaximumDate ( const QDate date)

Sets the value of the maximumDate property to date.

void QCalendarWidget::setMinimumDate ( const QDate date)

Sets the value of the minimumDate property to date.

void QCalendarWidget::setNavigationBarVisible ( bool  visible)
slot

Sets the value of the navigationBarVisible property to visible.

void QCalendarWidget::setSelectedDate ( const QDate date)
slot

Sets the value of the selectedDate property to date.

void QCalendarWidget::setSelectionMode ( SelectionMode  mode)

Sets the value of the selectionMode property to mode.

void QCalendarWidget::setVerticalHeaderFormat ( VerticalHeaderFormat  format)

Sets the value of the verticalHeaderFormat property to 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.

See also
weekdayTextFormat(), setHeaderTextFormat()
void QCalendarWidget::showNextMonth ( )
slot

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

See also
showPreviousMonth(), setCurrentPage(), setSelectedDate()
void QCalendarWidget::showNextYear ( )
slot

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

See also
showPreviousYear(), setCurrentPage(), setSelectedDate()
void QCalendarWidget::showPreviousMonth ( )
slot

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

See also
showNextMonth(), setCurrentPage(), setSelectedDate()
void QCalendarWidget::showPreviousYear ( )
slot

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

See also
showNextYear(), setCurrentPage(), setSelectedDate()
void QCalendarWidget::showSelectedDate ( )
slot

Shows the month of the selected date.

See also
selectedDate(), setCurrentPage()
void QCalendarWidget::showToday ( )
slot

Shows the month of the today's date.

See also
selectedDate(), setCurrentPage()
QSize QCalendarWidget::sizeHint ( ) const
overridevirtual

Reimplemented from QWidget::sizeHint()

void QCalendarWidget::updateCell ( const QDate date)
protected

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

See also
updateCells(), yearShown(), monthShown()
void QCalendarWidget::updateCells ( )
protected

Updates all visible cells unless updates are disabled.

See also
updateCell()
VerticalHeaderFormat QCalendarWidget::verticalHeaderFormat ( ) const

Returns the value of the verticalHeaderFormat property.

QTextCharFormat QCalendarWidget::weekdayTextFormat ( Qt::DayOfWeek  dayOfWeek) const

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

See also
setWeekdayTextFormat(), headerTextFormat()
int QCalendarWidget::yearShown ( ) const

Returns the year of the currently displayed month.

See also
monthShown(), setCurrentPage()

Property Documentation

QCalendarWidget::dateEditAcceptDelay

This property holds the time an inactive date edit is shown before its contents are accepted. By default the delay is defined to be 1500 milliseconds (1.5 seconds).

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.

PropertiesClass Methods
read dateEditAcceptDelay
write setDateEditAcceptDelay
QCalendarWidget::dateEditEnabled

This property holds whether the date edit popup is enabled. By default this property 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.

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
QCalendarWidget::dateEditAcceptDelay
PropertiesClass Methods
read isDateEditEnabled
write setDateEditEnabled
QCalendarWidget::firstDayOfWeek

This property holds a value identifying the day displayed in the first column. By default the day displayed in the first column is Sunday.

PropertiesClass Methods
read firstDayOfWeek
write setFirstDayOfWeek
QCalendarWidget::gridVisible

This property holds whether the grid is displayed. The default value is false.

QCalendarWidget *calendar;
calendar->setGridVisible(true);
PropertiesClass Methods
read isGridVisible
write setGridVisible
QCalendarWidget::horizontalHeaderFormat

This property holds the format of the horizontal header. The default value is QCalendarWidget::ShortDayNames.

PropertiesClass Methods
read horizontalHeaderFormat
write setHorizontalHeaderFormat
QCalendarWidget::maximumDate

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

QCalendarWidget *calendar;
calendar->setGridVisible(true);
calendar->setMaximumDate(QDate(2006, 7, 3));
See also
setDateRange()
PropertiesClass Methods
read maximumDate
write setMaximumDate
QCalendarWidget::minimumDate

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

QCalendarWidget *calendar;
calendar->setGridVisible(true);
calendar->setMinimumDate(QDate(2006, 6, 19));
See also
setDateRange()
PropertiesClass Methods
read minimumDate
write setMinimumDate
QCalendarWidget::navigationBarVisible

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.

PropertiesClass Methods
read isNavigationBarVisible
write setNavigationBarVisible
QCalendarWidget::selectedDate

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.

See also
setDateRange()
PropertiesClass Methods
read selectedDate
write setSelectedDate
QCalendarWidget::selectionMode

This property holds the way the user can select dates in the calendar. When this property is set to SelectionMode::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 SelectionMode::NoSelection the user will be unable to select dates, however a date can be selected programmatically. The default value is SelectionMode::SingleSelection.

PropertiesClass Methods
read selectionMode
write setSelectionMode
QCalendarWidget::verticalHeaderFormat

This property holds the format of the vertical header. The default value is VerticalHeaderFormat::ISOWeekNumbers.

PropertiesClass Methods
read verticalHeaderFormat
write setVerticalHeaderFormat