Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcalendarwidget.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCALENDARWIDGET_H
5#define QCALENDARWIDGET_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qwidget.h>
9#include <QtCore/qdatetime.h>
10
11QT_REQUIRE_CONFIG(calendarwidget);
12
14
15class QDate;
16class QTextCharFormat;
18
19class Q_WIDGETS_EXPORT QCalendarWidget : public QWidget
20{
23 Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate)
24 Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate RESET clearMinimumDate)
25 Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate RESET clearMaximumDate)
26 Q_PROPERTY(Qt::DayOfWeek firstDayOfWeek READ firstDayOfWeek WRITE setFirstDayOfWeek)
27 Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
28 Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
29 Q_PROPERTY(HorizontalHeaderFormat horizontalHeaderFormat READ horizontalHeaderFormat
30 WRITE setHorizontalHeaderFormat)
31 Q_PROPERTY(VerticalHeaderFormat verticalHeaderFormat READ verticalHeaderFormat
32 WRITE setVerticalHeaderFormat)
33 Q_PROPERTY(bool navigationBarVisible READ isNavigationBarVisible WRITE setNavigationBarVisible)
34 Q_PROPERTY(bool dateEditEnabled READ isDateEditEnabled WRITE setDateEditEnabled)
35 Q_PROPERTY(int dateEditAcceptDelay READ dateEditAcceptDelay WRITE setDateEditAcceptDelay)
36
37public:
44 Q_ENUM(HorizontalHeaderFormat)
45
48 ISOWeekNumbers
49 };
50 Q_ENUM(VerticalHeaderFormat)
51
54 SingleSelection
55 };
56 Q_ENUM(SelectionMode)
57
58 explicit QCalendarWidget(QWidget *parent = nullptr);
60
61 virtual QSize sizeHint() const override;
62 virtual QSize minimumSizeHint() const override;
63
64 QDate selectedDate() const;
65
66 int yearShown() const;
67 int monthShown() const;
68
69 QDate minimumDate() const;
71 void clearMinimumDate();
72
73 QDate maximumDate() const;
75 void clearMaximumDate();
76
77 Qt::DayOfWeek firstDayOfWeek() const;
78 void setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
79
80 bool isNavigationBarVisible() const;
81 bool isGridVisible() const;
82
83 QCalendar calendar() const;
84 void setCalendar(QCalendar calendar);
85
86 SelectionMode selectionMode() const;
87 void setSelectionMode(SelectionMode mode);
88
89 HorizontalHeaderFormat horizontalHeaderFormat() const;
90 void setHorizontalHeaderFormat(HorizontalHeaderFormat format);
91
92 VerticalHeaderFormat verticalHeaderFormat() const;
93 void setVerticalHeaderFormat(VerticalHeaderFormat format);
94
95 QTextCharFormat headerTextFormat() const;
96 void setHeaderTextFormat(const QTextCharFormat &format);
97
98 QTextCharFormat weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const;
99 void setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format);
100
101 QMap<QDate, QTextCharFormat> dateTextFormat() const;
102 QTextCharFormat dateTextFormat(QDate date) const;
103 void setDateTextFormat(QDate date, const QTextCharFormat &format);
104
105 bool isDateEditEnabled() const;
106 void setDateEditEnabled(bool enable);
107
108 int dateEditAcceptDelay() const;
109 void setDateEditAcceptDelay(int delay);
110
111protected:
112 bool event(QEvent *event) override;
113 bool eventFilter(QObject *watched, QEvent *event) override;
114 void mousePressEvent(QMouseEvent *event) override;
115 void resizeEvent(QResizeEvent * event) override;
116 void keyPressEvent(QKeyEvent * event) override;
117
118 virtual void paintCell(QPainter *painter, const QRect &rect, QDate date) const;
119 void updateCell(QDate date);
120 void updateCells();
121
122public Q_SLOTS:
123 void setSelectedDate(QDate date);
124 void setDateRange(QDate min, QDate max);
125 void setCurrentPage(int year, int month);
126 void setGridVisible(bool show);
127 void setNavigationBarVisible(bool visible);
128 void showNextMonth();
129 void showPreviousMonth();
130 void showNextYear();
131 void showPreviousYear();
132 void showSelectedDate();
133 void showToday();
134
139 void currentPageChanged(int year, int month);
140
141private:
142 Q_DECLARE_PRIVATE(QCalendarWidget)
143 Q_DISABLE_COPY(QCalendarWidget)
144
145 Q_PRIVATE_SLOT(d_func(), void _q_slotShowDate(QDate date))
146 Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(QDate date))
147 Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(QDate date, bool changeMonth))
148 Q_PRIVATE_SLOT(d_func(), void _q_editingFinished())
149 Q_PRIVATE_SLOT(d_func(), void _q_prevMonthClicked())
150 Q_PRIVATE_SLOT(d_func(), void _q_nextMonthClicked())
151 Q_PRIVATE_SLOT(d_func(), void _q_yearEditingFinished())
152 Q_PRIVATE_SLOT(d_func(), void _q_yearClicked())
153 Q_PRIVATE_SLOT(d_func(), void _q_monthChanged(QAction *act))
154
155};
156
158
159#endif // QCALENDARWIDGET_H
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date...
void clicked(QDate date)
This signal is emitted when a mouse button is clicked.
VerticalHeaderFormat
This enum type defines the various formats the vertical header can display.
void currentPageChanged(int year, int month)
This signal is emitted when the currently shown month is changed.
void selectionChanged()
This signal is emitted when the currently selected date is changed.
void activated(QDate date)
This signal is emitted whenever the user presses the Return or Enter key or double-clicks a date in t...
SelectionMode
This enum describes the types of selection offered to the user for selecting dates in the calendar.
HorizontalHeaderFormat
This enum type defines the various formats the horizontal header can display.
The QCalendar class describes calendar systems.
Definition qcalendar.h:53
\inmodule QtCore \reentrant
Definition qdatetime.h:29
\inmodule QtCore
Definition qcoreevent.h:45
The QKeyEvent class describes a key event.
Definition qevent.h:424
\inmodule QtGui
Definition qevent.h:196
\inmodule QtCore
Definition qobject.h:103
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qrect.h:30
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
\inmodule QtCore
Definition qsize.h:25
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QDate date
[1]
rect
[4]
Combined button and popup list for selecting options.
Definition qcompare.h:63
DayOfWeek
GLenum mode
GLboolean enable
GLint GLsizei GLsizei GLenum format
struct _cl_event * event
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_ENUMS(x)
#define Q_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
view show()
[18] //! [19]
QPainter painter(this)
[7]
calendar setMaximumDate(QDate(2006, 7, 3))
calendar setMinimumDate(QDate(2006, 6, 19))
QCalendarWidget * calendar
[0]
calendar setGridVisible(true)
calendar setDateRange(min, max)