summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/kernel/qwidget.cpp46
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp8
2 files changed, 29 insertions, 25 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 7c3c4fe8da..7136714d39 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -12305,21 +12305,20 @@ QPaintEngine *QWidget::paintEngine() const
*/
QPoint QWidget::mapToGlobal(const QPoint &pos) const
{
- int x = pos.x(), y = pos.y();
- const QWidget *w = this;
- while (w) {
#ifndef QT_NO_GRAPHICSVIEW
- const QWidgetPrivate *d = w->d_func();
- if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
- const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
- if (!views.isEmpty()) {
- const QPointF scenePos = d->extra->proxyWidget->mapToScene(QPoint(x, y));
- const QPoint viewPortPos = views.first()->mapFromScene(scenePos);
- return views.first()->viewport()->mapToGlobal(viewPortPos);
- }
+ Q_D(const QWidget);
+ if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
+ const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
+ if (!views.isEmpty()) {
+ const QPointF scenePos = d->extra->proxyWidget->mapToScene(pos);
+ const QPoint viewPortPos = views.first()->mapFromScene(scenePos);
+ return views.first()->viewport()->mapToGlobal(viewPortPos);
}
+ }
#endif // !QT_NO_GRAPHICSVIEW
-
+ int x = pos.x(), y = pos.y();
+ const QWidget *w = this;
+ while (w) {
QWindow *window = w->windowHandle();
if (window && window->handle())
return window->mapToGlobal(QPoint(x, y));
@@ -12341,21 +12340,20 @@ QPoint QWidget::mapToGlobal(const QPoint &pos) const
*/
QPoint QWidget::mapFromGlobal(const QPoint &pos) const
{
- int x = pos.x(), y = pos.y();
- const QWidget *w = this;
- while (w) {
#ifndef QT_NO_GRAPHICSVIEW
- const QWidgetPrivate *d = w->d_func();
- if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
- const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
- if (!views.isEmpty()) {
- const QPoint viewPortPos = views.first()->viewport()->mapFromGlobal(QPoint(x, y));
- const QPointF scenePos = views.first()->mapToScene(viewPortPos);
- return d->extra->proxyWidget->mapFromScene(scenePos).toPoint();
- }
+ Q_D(const QWidget);
+ if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) {
+ const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views();
+ if (!views.isEmpty()) {
+ const QPoint viewPortPos = views.first()->viewport()->mapFromGlobal(pos);
+ const QPointF scenePos = views.first()->mapToScene(viewPortPos);
+ return d->extra->proxyWidget->mapFromScene(scenePos).toPoint();
}
+ }
#endif // !QT_NO_GRAPHICSVIEW
-
+ int x = pos.x(), y = pos.y();
+ const QWidget *w = this;
+ while (w) {
QWindow *window = w->windowHandle();
if (window && window->handle())
return window->mapFromGlobal(QPoint(x, y));
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index cd40c5541c..f3a683fe8b 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -3684,6 +3684,7 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135
const QSize size = availableGeometry.size() / 5;
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setTransform(QTransform::fromScale(2, 2)); // QTBUG-50136, use transform.
view.setWindowTitle(QTest::currentTestFunction());
view.resize(size);
view.move(availableGeometry.bottomRight() - QPoint(size.width(), size.height()) - QPoint(100, 100));
@@ -3706,10 +3707,15 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135
QVERIFY2((viewCenter - embeddedCenterGlobal).manhattanLength() <= 2,
msgPointMismatch(embeddedCenterGlobal, viewCenter).constData());
- // Same test with child centered on embeddedWidget
+ // Same test with child centered on embeddedWidget. The correct
+ // mapping is not implemented yet, but at least make sure
+ // the roundtrip maptoGlobal()/mapFromGlobal() returns the same
+ // point since that is important for mouse event handling (QTBUG-50030,
+ // QTBUG-50136).
const QPoint childCenter = childWidget->rect().center();
const QPoint childCenterGlobal = childWidget->mapToGlobal(childCenter);
QCOMPARE(childWidget->mapFromGlobal(childCenterGlobal), childCenter);
+ QEXPECT_FAIL("", "Not implemented for child widgets of embedded widgets", Continue);
QVERIFY2((viewCenter - childCenterGlobal).manhattanLength() <= 4,
msgPointMismatch(childCenterGlobal, viewCenter).constData());
}