summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qfocusframe.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-11-08 14:11:11 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-11-27 14:59:52 +0000
commitf1812aad895ed2b8337a6d98d05623714680aba9 (patch)
tree9ad9d74dea7feb0775a03edae793a7c01ac3f10a /src/widgets/widgets/qfocusframe.cpp
parenta5e32f93759db5aff30994546cd1cc172e6a57dc (diff)
QFocusFrame: protect it from being moved around by accident
If a focus frame is set around a widget that exist inside a QAbstractItemView, both the focus frame and the widget will be scrolled when the table is scrolled (since the focus frame is a child of the view). The result is that after the widget has been scrolled (which will move the focus frame to the correct position as well), the focus frame will be scrolled next, and therefore away from the widget. This patch will catch this case by always adjusting the focus frame position when someone tries to move it. Trying to move the focus frame away from the widget it tracks will anyway be flaky. Fixes: QTBUG-63877 Change-Id: Ic2aacc4fafc219280e32092c258a7539d0db9cd0 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/widgets/widgets/qfocusframe.cpp')
-rw-r--r--src/widgets/widgets/qfocusframe.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/widgets/widgets/qfocusframe.cpp b/src/widgets/widgets/qfocusframe.cpp
index 8b8f4db86e..0992becdf0 100644
--- a/src/widgets/widgets/qfocusframe.cpp
+++ b/src/widgets/widgets/qfocusframe.cpp
@@ -335,7 +335,25 @@ QFocusFrame::eventFilter(QObject *o, QEvent *e)
/*! \reimp */
bool QFocusFrame::event(QEvent *e)
{
- return QWidget::event(e);
+ Q_D(QFocusFrame);
+
+ switch (e->type()) {
+ case QEvent::Move:
+ case QEvent::Resize:
+ if (d->widget) {
+ // When we're tracking a widget, we don't allow anyone to move the focus frame around.
+ // We do our best with event filters to make it stay on top of the widget, so trying to
+ // move the frame somewhere else will be flaky at best. This can e.g happen for general
+ // purpose code, like QAbstractScrollView, that bulk-moves all children a certain distance.
+ // So we need to call updateSize() when that happens to ensure that the focus frame stays
+ // on top of the widget.
+ d->updateSize();
+ }
+ break;
+ default:
+ return QWidget::event(e);
+ }
+ return true;
}
QT_END_NAMESPACE