diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-06-15 15:52:11 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-06-17 12:32:21 +0000 |
commit | fdb7a7b8d6518ec971ed058c63b71318d648a86e (patch) | |
tree | 5ad9ff142465804bd8e33c77bad4f05bed116c08 | |
parent | a56623bd09ae39c283a1fbe143dc571b4451d8b0 (diff) |
Make sure the focus rect is drawn
In windows style, the focus rect is drawn when the button is drawn,
but we are only drawing the bevel, so the focus rect was not drawn.
We move the logic of drawing the focus rect so that it is drawn when
drawing the bevel instead.
Also, we have to set the QStyle::State_KeyboardFocusChange in order
for the focus rect to be drawn
Change-Id: I4463ae1dd0f23ecc5bb0a84c563fda33dc6e93c8
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.cpp | 13 | ||||
-rw-r--r-- | src/imports/nativestyle/qstyle/qquickcommonstyle.cpp | 12 |
2 files changed, 15 insertions, 10 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp index 15fe4ede..4c7f404f 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.cpp +++ b/src/imports/nativestyle/items/qquickstyleitem.cpp @@ -40,6 +40,7 @@ #include <QtQuick/qsgninepatchnode.h> #include <QtQuick/private/qquickwindow_p.h> +#include <QtQuick/qquickwindow.h> #include <QtQuickTemplates2/private/qquickcontrol_p.h> #include <QtQuickTemplates2/private/qquickbutton_p.h> @@ -181,14 +182,18 @@ void QQuickStyleItem::initStyleOptionBase(QStyleOption &styleOption) styleOption.state |= QStyle::State_Active; // Note: not all controls inherit from QQuickControl (e.g QQuickTextField) - if (const auto quickControl = dynamic_cast<QQuickControl *>(m_control.data())) { + if (const auto quickControl = dynamic_cast<QQuickControl *>(m_control.data())) styleOption.direction = quickControl->isMirrored() ? Qt::RightToLeft : Qt::LeftToRight; - if (quickControl->isEnabled()) + + if (window()) { + if (m_control->isEnabled()) styleOption.state |= QStyle::State_Enabled; - if (quickControl->hasVisualFocus()) + if (m_control->hasActiveFocus()) styleOption.state |= QStyle::State_HasFocus; - if (quickControl->isUnderMouse()) + if (m_control->isUnderMouse()) styleOption.state |= QStyle::State_MouseOver; + // Should this depend on the focusReason (e.g. only TabFocus) ? + styleOption.state |= QStyle::State_KeyboardFocusChange; } qqc2Debug() << styleOption; diff --git a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp index 17af8763..16e05abd 100644 --- a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp +++ b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp @@ -1168,12 +1168,6 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, QStyleOptionButton subopt = *btn; subopt.rect = subElementRect(SE_PushButtonContents, btn); proxy()->drawControl(CE_PushButtonLabel, &subopt, p); - if (btn->state & State_HasFocus) { - QStyleOptionFocusRect fropt; - fropt.QStyleOption::operator=(*btn); - fropt.rect = subElementRect(SE_PushButtonFocusRect, btn); - proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p); - } } break; case CE_PushButtonBevel: @@ -1198,6 +1192,12 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, newBtn.rect = QRect(ir.right() - mbi + 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6); proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p); } + if (btn->state & State_HasFocus) { + QStyleOptionFocusRect fropt; + fropt.QStyleOption::operator=(*btn); + fropt.rect = subElementRect(SE_PushButtonFocusRect, btn); + proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p); + } } break; case CE_PushButtonLabel: |