Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickcombobox_p.h
Go to the documentation of this file.
1// Copyright (C) 2017 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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKCOMBOBOX_P_H
6#define QQUICKCOMBOBOX_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qloggingcategory.h>
20#include <QtQmlModels/private/qtqmlmodels-config_p.h>
21#include <QtQuickTemplates2/private/qquickcontrol_p.h>
22
24
26
28
29class QValidator;
30class QQuickPopup;
31class QQmlInstanceModel;
33class QQmlComponent;
34
35class Q_QUICKTEMPLATES2_EXPORT QQuickComboBox : public QQuickControl
36{
37 Q_OBJECT
38 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL)
39 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL)
40 Q_PROPERTY(QQmlInstanceModel *delegateModel READ delegateModel NOTIFY delegateModelChanged FINAL)
41 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL)
42 Q_PROPERTY(int highlightedIndex READ highlightedIndex NOTIFY highlightedIndexChanged FINAL)
43 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL)
44 Q_PROPERTY(QString currentText READ currentText NOTIFY currentTextChanged FINAL)
45 Q_PROPERTY(QString displayText READ displayText WRITE setDisplayText RESET resetDisplayText NOTIFY displayTextChanged FINAL)
46 Q_PROPERTY(QString textRole READ textRole WRITE setTextRole NOTIFY textRoleChanged FINAL)
47 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
48 Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL)
49 Q_PROPERTY(QQuickPopup *popup READ popup WRITE setPopup NOTIFY popupChanged FINAL)
50 // 2.1 (Qt 5.8)
51 Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL REVISION(2, 1))
52 // 2.2 (Qt 5.9)
53 Q_PROPERTY(bool down READ isDown WRITE setDown RESET resetDown NOTIFY downChanged FINAL REVISION(2, 2))
54 Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL REVISION(2, 2))
55 Q_PROPERTY(QString editText READ editText WRITE setEditText RESET resetEditText NOTIFY editTextChanged FINAL REVISION(2, 2))
56#if QT_CONFIG(validator)
57 Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL REVISION(2, 2))
58#endif
59 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION(2, 2))
60 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION(2, 2))
61 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL REVISION(2, 2))
62 // 2.5 (Qt 5.12)
63 Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5))
64 Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5))
65 Q_CLASSINFO("DeferredPropertyNames", "background,contentItem,indicator,popup")
66 // 2.14 (Qt 5.14)
67 Q_PROPERTY(QVariant currentValue READ currentValue WRITE setCurrentValue NOTIFY currentValueChanged FINAL REVISION(2, 14))
68 Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged FINAL REVISION(2, 14))
69 // 2.15 (Qt 5.15)
70 Q_PROPERTY(bool selectTextByMouse READ selectTextByMouse WRITE setSelectTextByMouse NOTIFY selectTextByMouseChanged FINAL REVISION(2, 15))
71 // 6.0 (Qt 6.0)
72 Q_PROPERTY(ImplicitContentWidthPolicy implicitContentWidthPolicy READ implicitContentWidthPolicy
73 WRITE setImplicitContentWidthPolicy NOTIFY implicitContentWidthPolicyChanged FINAL REVISION(6, 0))
74 // 6.12 (Qt 6.12)
75 Q_PROPERTY(bool highlightOnHover READ highlightOnHover WRITE setHighlightOnHover NOTIFY highlightOnHoverChanged FINAL REVISION(6, 12))
76 QML_NAMED_ELEMENT(ComboBox)
77 QML_ADDED_IN_VERSION(2, 0)
78
79public:
80 explicit QQuickComboBox(QQuickItem *parent = nullptr);
81 ~QQuickComboBox();
82
83 int count() const;
84
85 QVariant model() const;
86 void setModel(const QVariant &model);
87 QQmlInstanceModel *delegateModel() const;
88
89 bool isPressed() const;
90 void setPressed(bool pressed);
91
92 int highlightedIndex() const;
93
94 int currentIndex() const;
95 void setCurrentIndex(int index);
96
97 QString currentText() const;
98
99 QString displayText() const;
100 void setDisplayText(const QString &text);
101 void resetDisplayText();
102
103 QString textRole() const;
104 void setTextRole(const QString &role);
105
106 QString valueRole() const;
107 void setValueRole(const QString &role);
108
109 QQmlComponent *delegate() const;
110 void setDelegate(QQmlComponent *delegate);
111
112 QQuickItem *indicator() const;
113 void setIndicator(QQuickItem *indicator);
114
115 QQuickPopup *popup() const;
116 void setPopup(QQuickPopup *popup);
117
118 Q_INVOKABLE QString textAt(int index) const;
119 Q_INVOKABLE int find(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly) const;
120
121 // 2.1 (Qt 5.8)
122 bool isFlat() const;
123 void setFlat(bool flat);
124
125 // 2.2 (Qt 5.9)
126 bool isDown() const;
127 void setDown(bool down);
128 void resetDown();
129
130 bool isEditable() const;
131 void setEditable(bool editable);
132
133 QString editText() const;
134 void setEditText(const QString &text);
135 void resetEditText();
136
137#if QT_CONFIG(validator)
138 QValidator *validator() const;
139 void setValidator(QValidator *validator);
140#endif
141
142 Qt::InputMethodHints inputMethodHints() const;
143 void setInputMethodHints(Qt::InputMethodHints hints);
144
145 bool isInputMethodComposing() const;
146 bool hasAcceptableInput() const;
147
148 // 2.5 (Qt 5.12)
149 qreal implicitIndicatorWidth() const;
150 qreal implicitIndicatorHeight() const;
151
152 // 2.14 (Qt 5.14)
153 QVariant currentValue() const;
154 Q_REVISION(6, 10) void setCurrentValue(const QVariant &value);
155 Q_REVISION(2, 14) Q_INVOKABLE QVariant valueAt(int index) const;
156 Q_REVISION(2, 14) Q_INVOKABLE int indexOfValue(const QVariant &value) const;
157
158 // 2.15 (Qt 5.15)
159 bool selectTextByMouse() const;
160 void setSelectTextByMouse(bool canSelect);
161
162 // 6.0 (Qt 6.0)
163 enum ImplicitContentWidthPolicy {
164 ContentItemImplicitWidth,
165 WidestText,
166 WidestTextWhenCompleted
167 };
168 Q_ENUM(ImplicitContentWidthPolicy)
169
170 ImplicitContentWidthPolicy implicitContentWidthPolicy() const;
171 void setImplicitContentWidthPolicy(ImplicitContentWidthPolicy policy);
172
173 // 6.12
174 bool highlightOnHover() const;
175 void setHighlightOnHover(bool value);
176
177public Q_SLOTS:
178 void incrementCurrentIndex();
179 void decrementCurrentIndex();
180 Q_REVISION(2, 2) void selectAll();
181
182Q_SIGNALS:
183 void activated(int index);
184 void highlighted(int index);
185 void countChanged();
186 void modelChanged();
187 void delegateModelChanged();
188 void pressedChanged();
189 void highlightedIndexChanged();
190 void currentIndexChanged();
191 void currentTextChanged();
192 void displayTextChanged();
193 void textRoleChanged();
194 void delegateChanged();
195 void indicatorChanged();
196 void popupChanged();
197 // 2.1 (Qt 5.8)
198 Q_REVISION(2, 1) void flatChanged();
199 // 2.2 (Qt 5.9)
200 Q_REVISION(2, 2) void accepted();
201 Q_REVISION(2, 2) void downChanged();
202 Q_REVISION(2, 2) void editableChanged();
203 Q_REVISION(2, 2) void editTextChanged();
204#if QT_CONFIG(validator)
205 Q_REVISION(2, 2) void validatorChanged();
206#endif
207 Q_REVISION(2, 2) void inputMethodHintsChanged();
208 Q_REVISION(2, 2) void inputMethodComposingChanged();
209 Q_REVISION(2, 2) void acceptableInputChanged();
210 // 2.5 (Qt 5.12)
211 Q_REVISION(2, 5) void implicitIndicatorWidthChanged();
212 Q_REVISION(2, 5) void implicitIndicatorHeightChanged();
213 // 2.14 (Qt 5.14)
214 Q_REVISION(2, 14) void valueRoleChanged();
215 Q_REVISION(2, 14) void currentValueChanged();
216 // 2.15 (Qt 5.15)
217 Q_REVISION(2, 15) void selectTextByMouseChanged();
218 // 6.0 (Qt 6.0)
219 Q_REVISION(6, 0) void implicitContentWidthPolicyChanged();
220 // 6.12 (Qt 6.12)
221 Q_REVISION(6, 12) void highlightOnHoverChanged();
222
223protected:
224 bool eventFilter(QObject *object, QEvent *event) override;
225 void focusInEvent(QFocusEvent *event) override;
226 void focusOutEvent(QFocusEvent *event) override;
227#if QT_CONFIG(im)
228 void inputMethodEvent(QInputMethodEvent *event) override;
229#endif
230 void keyPressEvent(QKeyEvent *event) override;
231 void keyReleaseEvent(QKeyEvent *event) override;
232#if QT_CONFIG(wheelevent)
233 void wheelEvent(QWheelEvent *event) override;
234#endif
235 bool event(QEvent *e) override;
236
237 void componentComplete() override;
238 void itemChange(ItemChange change, const ItemChangeData &value) override;
239 void fontChange(const QFont &newFont, const QFont &oldFont) override;
240 void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override;
241 void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override;
242
243 QFont defaultFont() const override;
244
245#if QT_CONFIG(accessibility)
246 QAccessible::Role accessibleRole() const override;
247 void accessibilityActiveChanged(bool active) override;
248#endif
249
250private:
251 Q_DISABLE_COPY(QQuickComboBox)
252 Q_DECLARE_PRIVATE(QQuickComboBox)
253};
254
255QT_END_NAMESPACE
256
257#endif // QQUICKCOMBOBOX_P_H
QQuickComboBoxDelegateModel(QQuickComboBox *combo)
QVariant variantValue(int index, const QString &role) override
void itemDestroyed(QQuickItem *item) override
bool handleRelease(const QPointF &point, ulong timestamp) override
CurrentElementCriteria currentElementCriteria
QQuickDeferredPointer< QQuickPopup > popup
qreal calculateWidestTextWidth() const
static void hideOldPopup(QQuickPopup *popup)
void setInputMethodHints(Qt::InputMethodHints hints, bool force=false)
void setHighlightedIndex(int index, Highlighting highlight)
void createdItem(int index, QObject *object)
QString effectiveTextRole() const
virtual qreal getContentWidth() const override
void keySearch(const QString &text)
void handleUngrab() override
int match(int start, const QString &text, Qt::MatchFlags flags) const
QPalette defaultPalette() const override
bool handleMove(const QPointF &point, ulong timestamp) override
QQmlInstanceModel * delegateModel
void itemImplicitHeightChanged(QQuickItem *item) override
void togglePopup(bool accept)
void executePopup(bool complete=false)
void itemImplicitWidthChanged(QQuickItem *item) override
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
void executeIndicator(bool complete=false)
QQuickDeferredPointer< QQuickItem > indicator
void hidePopup(bool accept)
void setCurrentIndex(int index)
QLazilyAllocated< ExtraData > extra
std::optional< QPointer< QObject > > qobjectModelGuard
bool handlePress(const QPointF &point, ulong timestamp) override
void setCurrentItemAtIndex(int, Activation activate)
bool isValidIndex(int index) const
QString tryComplete(const QString &inputText)
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)
QT_REQUIRE_CONFIG(qml_delegate_model)
static QString popupName()
Qt::InputMethodHints inputMethodHints