diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2013-02-21 10:37:21 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-21 10:37:21 +0100 |
commit | 8fd1330029eafc3f9496febd1ac2597e786ba324 (patch) | |
tree | 00acd1c068972d2de0083933227fae77824f5447 /src/widgets/kernel/qstackedlayout.cpp | |
parent | f9fc180d505382e559ebca8a2e6dd09ea3ae52bc (diff) | |
parent | dcb710dd87ab15c3af803133ff2449902dbec036 (diff) |
Merge "Merge remote-tracking branch 'origin/stable' into dev" into refs/staging/dev
Diffstat (limited to 'src/widgets/kernel/qstackedlayout.cpp')
-rw-r--r-- | src/widgets/kernel/qstackedlayout.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp index cb2711c636..f38f0a6f08 100644 --- a/src/widgets/kernel/qstackedlayout.cpp +++ b/src/widgets/kernel/qstackedlayout.cpp @@ -300,7 +300,9 @@ void QStackedLayout::setCurrentIndex(int index) parent->setUpdatesEnabled(false); } - QWidget *fw = parent ? parent->window()->focusWidget() : 0; + QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0; + const bool focusWasOnOldPage = fw && (prev && prev->isAncestorOf(fw)); + if (prev) { prev->clearFocus(); if (d->stackingMode == StackOne) @@ -315,24 +317,25 @@ void QStackedLayout::setCurrentIndex(int index) // was somewhere on the outgoing widget. if (parent) { - if (fw && (prev && prev->isAncestorOf(fw))) { // focus was on old page + if (focusWasOnOldPage) { // look for the best focus widget we can find if (QWidget *nfw = next->focusWidget()) nfw->setFocus(); else { // second best: first child widget in the focus chain - QWidget *i = fw; - while ((i = i->nextInFocusChain()) != fw) { - if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus) - && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled() - && next->isAncestorOf(i)) { - i->setFocus(); - break; + if (QWidget *i = fw) { + while ((i = i->nextInFocusChain()) != fw) { + if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus) + && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled() + && next->isAncestorOf(i)) { + i->setFocus(); + break; + } } + // third best: incoming widget + if (i == fw ) + next->setFocus(); } - // third best: incoming widget - if (i == fw ) - next->setFocus(); } } } |