summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/kernel/qwidget.cpp14
-rw-r--r--src/gui/kernel/qwidget.h1
-rw-r--r--tests/auto/qwidget/tst_qwidget.cpp12
3 files changed, 27 insertions, 0 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index 09162ee..ce14c82 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -5897,6 +5897,8 @@ QWidget *QWidget::focusWidget() const
/*!
Returns the next widget in this widget's focus chain.
+
+ \sa previousInFocusChain
*/
QWidget *QWidget::nextInFocusChain() const
{
@@ -5904,6 +5906,18 @@ QWidget *QWidget::nextInFocusChain() const
}
/*!
+ Returns the previous widget in this widget's focus chain.
+
+ \sa nextInFocusChain
+
+ \since 4.6
+*/
+QWidget *QWidget::previousInFocusChain() const
+{
+ return const_cast<QWidget *>(d_func()->focus_prev);
+}
+
+/*!
\property QWidget::isActiveWindow
\brief whether this widget's window is the active window
diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h
index f54ebf9..309463e 100644
--- a/src/gui/kernel/qwidget.h
+++ b/src/gui/kernel/qwidget.h
@@ -539,6 +539,7 @@ public:
QWidget *focusWidget() const;
QWidget *nextInFocusChain() const;
+ QWidget *previousInFocusChain() const;
// drag and drop
bool acceptDrops() const;
diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp
index dfd0792..9197144 100644
--- a/tests/auto/qwidget/tst_qwidget.cpp
+++ b/tests/auto/qwidget/tst_qwidget.cpp
@@ -1544,6 +1544,10 @@ void tst_QWidget::focusChainOnReparent()
QCOMPARE(w, expectedOriginalChain[i]);
w = w->nextInFocusChain();
}
+ for (int i = 7; i >= 0; --i) {
+ w = w->previousInFocusChain();
+ QCOMPARE(w, expectedOriginalChain[i]);
+ }
QWidget window2;
child2->setParent(&window2);
@@ -1554,6 +1558,10 @@ void tst_QWidget::focusChainOnReparent()
QCOMPARE(w, expectedNewChain[i]);
w = w->nextInFocusChain();
}
+ for (int i = 4; i >= 0; --i) {
+ w = w->previousInFocusChain();
+ QCOMPARE(w, expectedNewChain[i]);
+ }
QWidget *expectedOldChain[5] = {&window, child1, child3, child4, &window};
w = &window;
@@ -1561,6 +1569,10 @@ void tst_QWidget::focusChainOnReparent()
QCOMPARE(w, expectedOldChain[i]);
w = w->nextInFocusChain();
}
+ for (int i = 4; i >= 0; --i) {
+ w = w->previousInFocusChain();
+ QCOMPARE(w, expectedOldChain[i]);
+ }
}