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
qquickroundbutton.cpp
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
6
7#include <QtQuickTemplates2/private/qquickbutton_p_p.h>
8
10
11/*!
12 \qmltype RoundButton
13 \inherits Button
14//! \nativetype QQuickRoundButton
15 \inqmlmodule QtQuick.Controls
16 \since 5.8
17 \ingroup qtquickcontrols-buttons
18 \brief A push-button control with rounded corners that can be clicked by the user.
19
20 \image qtquickcontrols-roundbutton.png
21
22 RoundButton is identical to \l Button, except that it has a \l radius property
23 which allows the corners to be rounded without having to customize the
24 \l background.
25
26 \snippet qtquickcontrols-roundbutton.qml 1
27
28 \sa {Customizing RoundButton}, {Button Controls}
29*/
30
32{
33 Q_DECLARE_PUBLIC(QQuickRoundButton)
34
35public:
37
39 bool explicitRadius = false;
40};
41
42void QQuickRoundButtonPrivate::setRadius(qreal newRadius)
43{
44 Q_Q(QQuickRoundButton);
45 const qreal oldRadius = radius;
46 if (newRadius < 0)
47 radius = qMax<qreal>(0, qMin<qreal>(width, height) / 2);
48 else
49 radius = newRadius;
50
51 if (!qFuzzyCompare(radius, oldRadius))
52 emit q->radiusChanged();
53}
54
55QQuickRoundButton::QQuickRoundButton(QQuickItem *parent)
56 : QQuickButton(*(new QQuickRoundButtonPrivate), parent)
57{
58}
59
60/*!
61 \qmlproperty real QtQuick.Controls::RoundButton::radius
62
63 This property holds the radius of the button.
64
65 To create a relatively square button that has slightly rounded corners,
66 use a small value, such as \c 3.
67
68 To create a completely circular button (the default), use a value that is
69 equal to half of the width or height of the button, and make the button's
70 width and height identical.
71
72 To reset this property back to the default value, set its value to
73 \c undefined.
74*/
75qreal QQuickRoundButton::radius() const
76{
77 Q_D(const QQuickRoundButton);
78 return d->radius;
79}
80
81void QQuickRoundButton::setRadius(qreal radius)
82{
83 Q_D(QQuickRoundButton);
84 d->explicitRadius = true;
85 d->setRadius(radius);
86}
87
88void QQuickRoundButton::resetRadius()
89{
90 Q_D(QQuickRoundButton);
91 d->explicitRadius = false;
92 d->setRadius();
93}
94
95void QQuickRoundButton::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
96{
97 Q_D(QQuickRoundButton);
98 QQuickControl::geometryChange(newGeometry, oldGeometry);
99 if (!d->explicitRadius)
100 d->setRadius();
101}
102
103QT_END_NAMESPACE
104
105#include "moc_qquickroundbutton_p.cpp"
A push-button control with rounded corners that can be clicked by the user.