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
qdatetimeedit.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 QDATETIMEEDIT_H
5#define QDATETIMEEDIT_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtCore/qtimezone.h>
9#include <QtCore/qcalendar.h>
10#include <QtCore/qvariant.h>
11#include <QtWidgets/qabstractspinbox.h>
12
13QT_REQUIRE_CONFIG(datetimeedit);
14
16
18class QStyleOptionSpinBox;
19class QCalendarWidget;
20
21class Q_WIDGETS_EXPORT QDateTimeEdit : public QAbstractSpinBox
22{
24
25 Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged USER true)
26 Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged)
27 Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY timeChanged)
28 Q_PROPERTY(QDateTime maximumDateTime READ maximumDateTime WRITE setMaximumDateTime
29 RESET clearMaximumDateTime)
30 Q_PROPERTY(QDateTime minimumDateTime READ minimumDateTime WRITE setMinimumDateTime
31 RESET clearMinimumDateTime)
32 Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate RESET clearMaximumDate)
33 Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate RESET clearMinimumDate)
34 Q_PROPERTY(QTime maximumTime READ maximumTime WRITE setMaximumTime RESET clearMaximumTime)
35 Q_PROPERTY(QTime minimumTime READ minimumTime WRITE setMinimumTime RESET clearMinimumTime)
36 Q_PROPERTY(Section currentSection READ currentSection WRITE setCurrentSection)
37 Q_PROPERTY(Sections displayedSections READ displayedSections)
38 Q_PROPERTY(QString displayFormat READ displayFormat WRITE setDisplayFormat)
39 Q_PROPERTY(bool calendarPopup READ calendarPopup WRITE setCalendarPopup)
40 Q_PROPERTY(int currentSectionIndex READ currentSectionIndex WRITE setCurrentSectionIndex)
41 Q_PROPERTY(int sectionCount READ sectionCount)
42#if QT_DEPRECATED_SINCE(6, 10)
43 Q_PROPERTY(Qt::TimeSpec timeSpec READ timeSpec WRITE setTimeSpec)
44#endif
45 Q_PROPERTY(QTimeZone timeZone READ timeZone WRITE setTimeZone)
46public:
47 enum Section { // a sub-type of QDateTimeParser's like-named enum.
48 NoSection = 0x0000,
49 AmPmSection = 0x0001,
50 MSecSection = 0x0002,
51 SecondSection = 0x0004,
52 MinuteSection = 0x0008,
53 HourSection = 0x0010,
54 DaySection = 0x0100,
55 MonthSection = 0x0200,
56 YearSection = 0x0400,
57 TimeSections_Mask = AmPmSection|MSecSection|SecondSection|MinuteSection|HourSection,
58 DateSections_Mask = DaySection|MonthSection|YearSection
59 };
60 Q_ENUM(Section)
61
62 Q_DECLARE_FLAGS(Sections, Section)
63 Q_FLAG(Sections)
64
65 explicit QDateTimeEdit(QWidget *parent = nullptr);
66 explicit QDateTimeEdit(const QDateTime &dt, QWidget *parent = nullptr);
67 explicit QDateTimeEdit(QDate d, QWidget *parent = nullptr);
68 explicit QDateTimeEdit(QTime t, QWidget *parent = nullptr);
70
71 QDateTime dateTime() const;
72 QDate date() const;
73 QTime time() const;
74
75 QCalendar calendar() const;
76 void setCalendar(QCalendar calendar);
77
78 QDateTime minimumDateTime() const;
79 void clearMinimumDateTime();
80 void setMinimumDateTime(const QDateTime &dt);
81
82 QDateTime maximumDateTime() const;
83 void clearMaximumDateTime();
84 void setMaximumDateTime(const QDateTime &dt);
85
86 void setDateTimeRange(const QDateTime &min, const QDateTime &max);
87
88 QDate minimumDate() const;
89 void setMinimumDate(QDate min);
90 void clearMinimumDate();
91
92 QDate maximumDate() const;
93 void setMaximumDate(QDate max);
94 void clearMaximumDate();
95
96 void setDateRange(QDate min, QDate max);
97
98 QTime minimumTime() const;
99 void setMinimumTime(QTime min);
100 void clearMinimumTime();
101
102 QTime maximumTime() const;
103 void setMaximumTime(QTime max);
104 void clearMaximumTime();
105
106 void setTimeRange(QTime min, QTime max);
107
108 Sections displayedSections() const;
109 Section currentSection() const;
110 Section sectionAt(int index) const;
111 void setCurrentSection(Section section);
112
113 int currentSectionIndex() const;
114 void setCurrentSectionIndex(int index);
115
116 QCalendarWidget *calendarWidget() const;
117 void setCalendarWidget(QCalendarWidget *calendarWidget);
118
119 int sectionCount() const;
120
121 void setSelectedSection(Section section);
122
123 QString sectionText(Section section) const;
124
125 QString displayFormat() const;
126 void setDisplayFormat(const QString &format);
127
128 bool calendarPopup() const;
129 void setCalendarPopup(bool enable);
130
131#if QT_DEPRECATED_SINCE(6, 10)
132 QT_DEPRECATED_VERSION_X_6_10("Use timeZone() instead")
133 Qt::TimeSpec timeSpec() const;
134 QT_DEPRECATED_VERSION_X_6_10("Use setTimeZone() instead")
135 void setTimeSpec(Qt::TimeSpec spec);
136#endif
137 QTimeZone timeZone() const;
138 void setTimeZone(const QTimeZone &zone);
139
140 QSize sizeHint() const override;
141
142 void clear() override;
143 void stepBy(int steps) override;
144
145 bool event(QEvent *event) override;
150
151public Q_SLOTS:
152 void setDateTime(const QDateTime &dateTime);
153 void setDate(QDate date);
154 void setTime(QTime time);
155
156protected:
157 void keyPressEvent(QKeyEvent *event) override;
158#if QT_CONFIG(wheelevent)
159 void wheelEvent(QWheelEvent *event) override;
160#endif
161 void focusInEvent(QFocusEvent *event) override;
162 bool focusNextPrevChild(bool next) override;
163 QValidator::State validate(QString &input, int &pos) const override;
164 void fixup(QString &input) const override;
165
166 virtual QDateTime dateTimeFromText(const QString &text) const;
167 virtual QString textFromDateTime(const QDateTime &dt) const;
168 StepEnabled stepEnabled() const override;
169 void mousePressEvent(QMouseEvent *event) override;
170 void paintEvent(QPaintEvent *event) override;
171 void initStyleOption(QStyleOptionSpinBox *option) const override;
172
173 QDateTimeEdit(const QVariant &val, QMetaType::Type parserType, QWidget *parent = nullptr);
174private:
175 Q_DECLARE_PRIVATE(QDateTimeEdit)
176 Q_DISABLE_COPY(QDateTimeEdit)
177
178 Q_PRIVATE_SLOT(d_func(), void _q_resetButton())
179};
180
181class Q_WIDGETS_EXPORT QTimeEdit : public QDateTimeEdit
182{
184 Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY userTimeChanged USER true)
185public:
186 explicit QTimeEdit(QWidget *parent = nullptr);
187 explicit QTimeEdit(QTime time, QWidget *parent = nullptr);
188 ~QTimeEdit();
189
192};
193
194class Q_WIDGETS_EXPORT QDateEdit : public QDateTimeEdit
195{
197 Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY userDateChanged USER true)
198public:
199 explicit QDateEdit(QWidget *parent = nullptr);
200 explicit QDateEdit(QDate date, QWidget *parent = nullptr);
201 ~QDateEdit();
202
205};
206
207Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeEdit::Sections)
208
210
211#endif // QDATETIMEEDIT_H
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date...
The QCalendar class describes calendar systems.
Definition qcalendar.h:53
The QDateEdit class provides a widget for editing dates based on the QDateTimeEdit widget.
void userDateChanged(QDate date)
This signal only exists to fully implement the date Q_PROPERTY on the class.
The QDateTimeEdit class provides a widget for editing dates and times.
void dateTimeChanged(const QDateTime &dateTime)
This signal is emitted whenever the date or time is changed.
Section
\value NoSection \value AmPmSection \value MSecSection \value SecondSection \value MinuteSection \val...
void dateChanged(QDate date)
This signal is emitted whenever the date is changed.
void timeChanged(QTime time)
This signal is emitted whenever the time is changed.
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore \reentrant
Definition qdatetime.h:29
\inmodule QtCore
Definition qcoreevent.h:45
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
The QKeyEvent class describes a key event.
Definition qevent.h:424
Type
\macro Q_DECLARE_OPAQUE_POINTER(PointerType)
Definition qmetatype.h:345
\inmodule QtGui
Definition qevent.h:196
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTimeEdit class provides a widget for editing times based on the QDateTimeEdit widget.
void userTimeChanged(QTime time)
This signal only exists to fully implement the time Q_PROPERTY on the class.
\inmodule QtCore
Definition qtimezone.h:26
\inmodule QtCore \reentrant
Definition qdatetime.h:215
State
This enum type defines the states in which a validated string can exist.
Definition qvalidator.h:30
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
b clear()
QString text
QDate date
[1]
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
static void setDateTime(QDateTimeData &d, QDate date, QTime time)
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
GLuint index
[2]
GLboolean enable
GLint GLsizei GLsizei GLenum format
struct _cl_event * event
GLuint GLfloat * val
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint GLenum option
GLenum GLenum GLenum input
#define QT_REQUIRE_CONFIG(feature)
#define QT_DEPRECATED_VERSION_X_6_10(text)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_FLAG(x)
#define Q_SLOTS
#define Q_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
QDateTime dateTime
[12]
spinBox stepBy(1)
calendar setMaximumDate(QDate(2006, 7, 3))
calendar setMinimumDate(QDate(2006, 6, 19))
QCalendarWidget * calendar
[0]
calendar setDateRange(min, max)
setMinimumDateTime(min)
[1]
setDateTimeRange(min, max)
[0]
setTimeRange(min, max)
[4]
dateEdit setDisplayFormat("yyyy.MM.dd")
setMaximumTime(max)
setMaximumDateTime(max)
setMinimumTime(min)
[5]