diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-09-28 13:13:57 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-09-28 13:17:08 (GMT) |
commit | 6e5c9afdb16e44d55683794442e66681f60d373b (patch) | |
tree | a14476334176dcc5fc7f334d97235247c32ca8f1 /src | |
parent | 58b40ab2220b9af4d2e679f23f07e425f9075dbd (diff) | |
download | Qt-6e5c9afdb16e44d55683794442e66681f60d373b.zip Qt-6e5c9afdb16e44d55683794442e66681f60d373b.tar.gz Qt-6e5c9afdb16e44d55683794442e66681f60d373b.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/qcalendarwidget.cpp | 20 |
1 files 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<QMouseEvent *>(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<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; + } + } } return QWidget::eventFilter(watched, event); } |