diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-01-09 15:01:16 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-02-12 11:26:22 +0000 |
commit | 7faec58d5cccf7e7a5f92116f70cc504821711af (patch) | |
tree | 76c9cd52722124ab685feef5c34c9cdac2c5c76d /src/widgets/widgets/qcalendarwidget.cpp | |
parent | 2e12bfdc1e537bb3cc027eed14500fe5724ab30f (diff) |
Fix crash when using Qt Virtual Keyboard with QCalendarWidget
For some reason, QCalendarWidget gets filtered press events that were
intended for Qt Virtual Keyboard's input panel (QQuickView), so we have
to make sure that the window is indeed a QWidget - no static_cast.
Change-Id: Ibc9dce956918ac50d1fed8231a445b7338aef09c
Fixes: QTBUG-72925
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/widgets/qcalendarwidget.cpp')
-rw-r--r-- | src/widgets/widgets/qcalendarwidget.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 4946969360..2ff383d9c7 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -3063,19 +3063,22 @@ bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event) { Q_D(QCalendarWidget); if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) { + // We can get filtered press events that were intended for Qt Virtual Keyboard's + // input panel (QQuickView), so we have to make sure that the window is indeed a QWidget - no static_cast. + // In addition, as we have a event filter on the whole application we first make sure that the top level widget + // of both this and the watched widget are the same to decide if we should finish the year edition. QWidget *tlw = window(); - QWidget *widget = static_cast<QWidget*>(watched); - //as we have a event filter on the whole application we first make sure that the top level widget - //of both this and the watched widget are the same to decide if we should finish the year edition. - if (widget->window() == tlw) { - QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); - QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); - if (!geom.contains(mousePos)) { - event->accept(); - d->_q_yearEditingFinished(); - setFocus(); - return true; - } + QWidget *widget = qobject_cast<QWidget *>(watched); + if (!widget || widget->window() != tlw) + return QWidget::eventFilter(watched, event); + + QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); + QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); + if (!geom.contains(mousePos)) { + event->accept(); + d->_q_yearEditingFinished(); + setFocus(); + return true; } } return QWidget::eventFilter(watched, event); |