diff options
-rw-r--r-- | src/templates/qquickbutton.cpp | 34 | ||||
-rw-r--r-- | src/templates/qquickbutton_p.h | 7 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_button.qml | 9 |
3 files changed, 50 insertions, 0 deletions
diff --git a/src/templates/qquickbutton.cpp b/src/templates/qquickbutton.cpp index 179e5bcd..7ec87cbf 100644 --- a/src/templates/qquickbutton.cpp +++ b/src/templates/qquickbutton.cpp @@ -83,11 +83,45 @@ QT_BEGIN_NAMESPACE class QQuickButtonPrivate : public QQuickAbstractButtonPrivate { +public: + QQuickButtonPrivate(); + + bool highlighted; }; +QQuickButtonPrivate::QQuickButtonPrivate() : + highlighted(false) +{ +} + QQuickButton::QQuickButton(QQuickItem *parent) : QQuickAbstractButton(*(new QQuickButtonPrivate), parent) { } +/*! + \qmlproperty bool Qt.labs.controls::Button::highlighted + + This property holds whether the button is highlighted. + + A button can be highlighted in order to draw the user's attention towards + it. It has no effect on keyboard interaction. + + The default value is \c false. +*/ +bool QQuickButton::isHighlighted() const +{ + Q_D(const QQuickButton); + return d->highlighted; +} + +void QQuickButton::setHighlighted(bool highlighted) +{ + Q_D(QQuickButton); + if (highlighted != d->highlighted) { + d->highlighted = highlighted; + emit highlightedChanged(); + } +} + QT_END_NAMESPACE diff --git a/src/templates/qquickbutton_p.h b/src/templates/qquickbutton_p.h index 1ee96a07..7ca0252b 100644 --- a/src/templates/qquickbutton_p.h +++ b/src/templates/qquickbutton_p.h @@ -57,10 +57,17 @@ class QQuickButtonPrivate; class Q_LABSTEMPLATES_EXPORT QQuickButton : public QQuickAbstractButton { Q_OBJECT + Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) public: explicit QQuickButton(QQuickItem *parent = Q_NULLPTR); + bool isHighlighted() const; + void setHighlighted(bool highlighted); + +Q_SIGNALS: + void highlightedChanged(); + private: Q_DISABLE_COPY(QQuickButton) Q_DECLARE_PRIVATE(QQuickButton) diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml index 76d45e03..b5b37156 100644 --- a/tests/auto/controls/data/tst_button.qml +++ b/tests/auto/controls/data/tst_button.qml @@ -290,4 +290,13 @@ TestCase { control.destroy() } + + function test_highlighted() { + var control = button.createObject(testCase) + verify(control) + compare(control.highlighted, false) + + control.highlighted = true + compare(control.highlighted, true) + } } |