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
qquickstyleitemsearchfield.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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
6
7#include <private/qquickindicatorbutton_p.h>
8
10
11QFont QQuickStyleItemSearchField::styleFont(QQuickItem *control) const
12{
13 return style()->font(QStyle::CE_PushButtonLabel, controlSize(control));
14}
15
16void QQuickStyleItemSearchField::connectToControl() const
17{
18 QQuickStyleItem::connectToControl();
19 auto searchField = control<QQuickSearchField>();
20 connect(searchField->searchIndicator(), &QQuickIndicatorButton::pressedChanged, this, &QQuickStyleItem::markImageDirty);
21 connect(searchField->clearIndicator(), &QQuickIndicatorButton::pressedChanged, this, &QQuickStyleItem::markImageDirty);
22 connect(searchField, &QQuickSearchField::textChanged, this, &QQuickStyleItem::markImageDirty);
23
24}
25
26void QQuickStyleItemSearchField::paintEvent(QPainter *painter) const
27{
28 QStyleOptionSearchField styleOption;
29 initStyleOption(styleOption);
30 style()->drawComplexControl(QStyle::CC_SearchField, &styleOption, painter);
31}
32
33StyleItemGeometry QQuickStyleItemSearchField::calculateGeometry() {
34 QStyleOptionSearchField styleOption;
35 initStyleOption(styleOption);
36 StyleItemGeometry geometry;
37
38 geometry.minimumSize = style()->sizeFromContents(QStyle::CT_SearchField, &styleOption, QSize(0, 0));
39
40 if (styleOption.subControls == QStyle::SC_SearchFieldFrame) {
41 geometry.implicitSize = style()->sizeFromContents(QStyle::CT_SearchField, &styleOption, contentSize());
42 styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
43 geometry.contentRect = style()->subControlRect(QStyle::CC_SearchField, &styleOption, QStyle::SC_SearchFieldEditField);
44 geometry.layoutRect = style()->subElementRect(QStyle::SE_SearchFieldLayoutItem, &styleOption);
45 geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CC_SearchField, &styleOption, geometry.minimumSize);
46 geometry.focusFrameRadius = style()->pixelMetric(QStyle::PM_SearchFieldFocusFrameRadius, &styleOption);
47 } else {
48 geometry.implicitSize = geometry.minimumSize;
49 }
50
51 return geometry;
52}
53
54void QQuickStyleItemSearchField::initStyleOption(QStyleOptionSearchField &styleOption) const {
55 initStyleOptionBase(styleOption);
56 auto searchField = control<QQuickSearchField>();
57
58 styleOption.text = searchField->text();
59
60 switch (m_subControl) {
61 case Frame:
62 styleOption.subControls = QStyle::SC_SearchFieldFrame;
63 styleOption.frame = true;
64 break;
65 case Search:
66 styleOption.subControls = QStyle::SC_SearchFieldSearch;
67 break;
68 case Clear:
69 styleOption.subControls = QStyle::SC_SearchFieldClear;
70 break;
71 }
72
73 if (searchField->searchIndicator()->isPressed()) {
74 styleOption.activeSubControls = QStyle::SC_SearchFieldSearch;
75 styleOption.state |= QStyle::State_Sunken;
76 } else if (searchField->clearIndicator()->isPressed()) {
77 styleOption.activeSubControls = QStyle::SC_SearchFieldClear;
78 styleOption.state |= QStyle::State_Sunken;
79 }
80}
81
82QT_END_NAMESPACE
83
84#include "moc_qquickstyleitemsearchfield_p.cpp"
Combined button and popup list for selecting options.