From 6e5c9afdb16e44d55683794442e66681f60d373b Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 28 Sep 2009 15:13:57 +0200 Subject: Impossible to interact with the year on QCalendarWidget on GraphicsView The problem is that it is using mapToGlobal to translate a mouse position andthat doesn't work well when the widget is mebedded inside graphics view. Task-number: QT-2218 Reviewed-by: Bjoern Erik Nilsen --- src/gui/widgets/qcalendarwidget.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/qcalendarwidget.cpp b/src/gui/widgets/qcalendarwidget.cpp index 71588c4..08ed7f6 100644 --- a/src/gui/widgets/qcalendarwidget.cpp +++ b/src/gui/widgets/qcalendarwidget.cpp @@ -3022,11 +3022,21 @@ bool QCalendarWidget::event(QEvent *event) bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event) { Q_D(QCalendarWidget); - if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus() && !QRect(d->yearEdit->mapToGlobal(QPoint(0, 0)), d->yearEdit->size()).contains(static_cast(event)->globalPos())) { - event->accept(); - d->_q_yearEditingFinished(); - setFocus(); - return true; + if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) { + QWidget *tlw = window(); + QWidget *widget = static_cast(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(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); } -- cgit v0.12