From 38c8af7231823429ca6cb9ea6418e2dcef3691a0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 22 Dec 2015 17:15:57 +0100 Subject: Revert "Fix global coordinate mapping for child widgets in QGraphicsView." This reverts commit 56aad2ad6074237537fecf10d0cda0f3872e7f71. QWidget::mapFromGlobal() does not work correctly when the widget is a child widget of another widget embedded into a QGraphicsView with a transformation (scaling/rotation). It starts applying offsets going up the widget tree (just as mapToGlobal) until it hits the embedded widget not taking into account the transformation. It would need to go in from to top to bottom or better be reimplemented such that a QTransform for mapping coordinates from/to global is determined which is then applied in reverse. Task-number: QTBUG-50030 Task-number: QTBUG-50136 Change-Id: Iadeb891d793be1938c64942bfbf38d541a281c33 Reviewed-by: Marc Mutz --- src/widgets/kernel/qwidget.cpp | 46 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') 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 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 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 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 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)); -- cgit v1.2.3 From 7b63c45df58a97bb3e800dd5fe20f41e11f92c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20Szczygie=C5=82?= Date: Sat, 2 Jan 2016 23:04:09 +0100 Subject: QtWidgets: Don't show window of native widget with WA_OutsideWSRange This patch prevents visibility of native widgets which for some reasons has width or height of 0. Due to async expose event in Qt5 we must force "hide_sys()" during resizing for widgets with WA_OutsideWSRange flag. This avoid problems for non-native and visible widgets which are converted to native and then resized: child->winId(); child->resize(0, 0); Task-number: QTBUG-49445 Change-Id: Ied62a4f253f89447941b2dc03316db8c168f4bb5 Reviewed-by: Ulf Hermann --- src/widgets/kernel/qwidget.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 229cfc0f85..d2e760da90 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1487,9 +1487,12 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO if (extra && !extra->mask.isEmpty()) setMask_sys(extra->mask); - // If widget is already shown, set window visible, too - if (q->isVisible()) + if (data.crect.width() == 0 || data.crect.height() == 0) { + q->setAttribute(Qt::WA_OutsideWSRange, true); + } else if (q->isVisible()) { + // If widget is already shown, set window visible, too win->setVisible(true); + } } #ifdef Q_OS_WIN @@ -7210,7 +7213,7 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) if (q->isWindow() || q->windowHandle()) { if (!(data.window_state & Qt::WindowFullScreen) && (w == 0 || h == 0)) { q->setAttribute(Qt::WA_OutsideWSRange, true); - if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) + if (q->isVisible()) hide_sys(); data.crect = QRect(x, y, w, h); } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) { @@ -7927,8 +7930,10 @@ void QWidgetPrivate::show_sys() else QApplication::postEvent(q, new QUpdateLaterEvent(q->rect())); - if (!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow)) + if ((!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow)) + || q->testAttribute(Qt::WA_OutsideWSRange)) { return; + } if (window) { if (q->isWindow()) -- cgit v1.2.3