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
qquickstyleitemtextfield.cpp
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
5
7
12
20
22{
23 QStyleOptionFrame styleOption;
24 initStyleOption(styleOption);
25 StyleItemGeometry geometry;
26
27 geometry.minimumSize = style()->sizeFromContents(QStyle::CT_LineEdit, &styleOption, QSize(0, 0));
28
29 // Inspired by QLineEdit::sizeHint()
30 QFontMetricsF fm(styleFont(const_cast<QQuickItem*>(control<QQuickItem>())));
31 const QSize sz(qCeil(fm.horizontalAdvance(QLatin1Char('x')) * 17),
33 geometry.implicitSize = style()->sizeFromContents(QStyle::CT_LineEdit, &styleOption, sz);
34
35 styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
36 geometry.layoutRect = styleOption.rect;
37 geometry.contentRect = style()->subElementRect(QStyle::SE_LineEditContents, &styleOption);
38 geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CE_ShapedFrame, &styleOption, geometry.minimumSize);
39 geometry.focusFrameRadius = style()->pixelMetric(QStyle::PM_TextFieldFocusFrameRadius, &styleOption);
40
41 return geometry;
42}
43
45{
46 QStyleOptionFrame styleOption;
47 initStyleOption(styleOption);
48 style()->drawPrimitive(QStyle::PE_PanelLineEdit, &styleOption, painter);
49}
50
51void QQuickStyleItemTextField::initStyleOption(QStyleOptionFrame &styleOption) const
52{
53 initStyleOptionBase(styleOption);
54 auto textField = control<QQuickTextField>();
55
56 styleOption.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &styleOption);
57 styleOption.midLineWidth = 0;
58 styleOption.state |= QStyle::State_Sunken;
59 if (textField->isReadOnly())
60 styleOption.state |= QStyle::State_ReadOnly;
61}
62
64
65#include "moc_qquickstyleitemtextfield.cpp"
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:22
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
void focusChanged(bool)
void connectToControl() const override
QFont styleFont(QQuickItem *control) const override
void paintEvent(QPainter *painter) const override
StyleItemGeometry calculateGeometry() override
virtual void connectToControl() const
QSize contentSize() const
static QStyle::State controlSize(QQuickItem *item)
void initStyleOptionBase(QStyleOption &styleOption) const
QQuickItem * control
static QStyle * style()
void readOnlyChanged(bool isReadOnly)
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
\variable QStyleOptionFocusRect::backgroundColor
QStyle::State state
@ State_Sunken
Definition qstyle.h:69
@ State_ReadOnly
Definition qstyle.h:94
@ CT_LineEdit
Definition qstyle.h:561
@ CE_ShapedFrame
Definition qstyle.h:232
@ CE_ComboBoxLabel
Definition qstyle.h:221
@ PM_DefaultFrameWidth
Definition qstyle.h:420
@ PE_PanelLineEdit
Definition qstyle.h:122
@ SE_LineEditContents
Definition qstyle.h:281
Combined button and popup list for selecting options.
int qCeil(T v)
Definition qmath.h:36
QPainter painter(this)
[7]
\inmodule QtCore \reentrant
Definition qchar.h:18