From ab97a44b6ae5cc826460f3704669383afd398594 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 3 Dec 2012 17:03:02 +1000 Subject: Clear focus of GraphicsItem focus scopes and their children. A focus scope has effective focus if one of its children is the focus item, clearFocus() should remove effective focus from an item and its children not just from the focus item. Task-number: QTBUG-28328 Change-Id: I62a292eff000151e50b2f5221e22f326a380fc3a Reviewed-by: Martin Jones --- src/widgets/graphicsview/qgraphicsitem.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index c30435e56a..f9b8cb83da 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -3313,6 +3313,12 @@ void QGraphicsItem::clearFocus() */ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenByParentPanel) { + QGraphicsItem *subFocusItem = q_ptr; + if (flags & QGraphicsItem::ItemIsFocusScope) { + while (subFocusItem->d_ptr->focusScopeItem) + subFocusItem = subFocusItem->d_ptr->focusScopeItem; + } + if (giveFocusToParent) { // Pass focus to the closest parent focus scope if (!inDestructor) { @@ -3321,10 +3327,10 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB if (p->flags() & QGraphicsItem::ItemIsFocusScope) { if (p->d_ptr->focusScopeItem == q_ptr) { p->d_ptr->focusScopeItem = 0; - if (!q_ptr->hasFocus()) //if it has focus, focusScopeItemChange is called elsewhere + if (!subFocusItem->hasFocus()) //if it has focus, focusScopeItemChange is called elsewhere focusScopeItemChange(false); } - if (q_ptr->hasFocus()) + if (subFocusItem->hasFocus()) p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false, /* focusFromHide = */ false); return; @@ -3334,7 +3340,7 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB } } - if (q_ptr->hasFocus()) { + if (subFocusItem->hasFocus()) { // Invisible items with focus must explicitly clear subfocus. if (!hiddenByParentPanel) clearSubFocus(q_ptr); -- cgit v1.2.3