aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickwidgets
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@theqtcompany.com>2015-03-30 14:14:00 +0200
committerChristian Stromme <christian.stromme@theqtcompany.com>2015-04-13 20:28:00 +0000
commitb902f540cda4bb523297a7a5c59520be06f30a1a (patch)
tree434fd73ec701e0d85e6009f0affd8f0471a8d506 /src/quickwidgets
parent1bff3496b172b041fcedbef0893c1d0de6c4fbc5 (diff)
Match the offscreen windows position to the QQuickWidget position.
The position of the offscreen window would always be set to 0,0, making it impossible to get the actual position of the scene. With this change, it will be possible for child windows or items in the scene to correctly calculate their global position. Change-Id: Ibd3ff03880209047776e86ad889b40cbf79c3e6e Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/quickwidgets')
-rw-r--r--src/quickwidgets/qquickwidget.cpp26
-rw-r--r--src/quickwidgets/qquickwidget_p.h1
2 files changed, 26 insertions, 1 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index b472664068..8b7a42de57 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -623,6 +623,22 @@ void QQuickWidgetPrivate::updateSize()
}
}
+/*!
+ \internal
+
+ Update the position of the offscreen window, so it matches the position of the QQuickWidget.
+ */
+void QQuickWidgetPrivate::updatePosition()
+{
+ Q_Q(QQuickWidget);
+ if (offscreenWindow == 0)
+ return;
+
+ const QPoint &pos = q->mapToGlobal(QPoint(0, 0));
+ if (offscreenWindow->position() != pos)
+ offscreenWindow->setPosition(pos);
+}
+
QSize QQuickWidgetPrivate::rootObjectSize() const
{
QSize rootObjectSize(0,0);
@@ -747,7 +763,11 @@ void QQuickWidget::createFramebufferObject()
d->fbo = new QOpenGLFramebufferObject(fboSize, format);
}
- d->offscreenWindow->setGeometry(0, 0, width(), height());
+ // Even though this is just an offscreen window we should set the position on it, as it might be
+ // useful for an item to know the actual position of the scene.
+ // Note: The position will be update when we get a move event (see: updatePosition()).
+ const QPoint &globalPos = mapToGlobal(QPoint(0, 0));
+ d->offscreenWindow->setGeometry(globalPos.x(), globalPos.y(), width(), height());
d->offscreenWindow->setRenderTarget(d->fbo);
if (samples > 0)
@@ -1100,6 +1120,10 @@ bool QQuickWidget::event(QEvent *e)
}
break;
+ case QEvent::Move:
+ d->updatePosition();
+ break;
+
default:
break;
}
diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h
index c16ce2fece..6a5601e479 100644
--- a/src/quickwidgets/qquickwidget_p.h
+++ b/src/quickwidgets/qquickwidget_p.h
@@ -73,6 +73,7 @@ public:
void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
void initResize();
void updateSize();
+ void updatePosition();
void updateFrambufferObjectSize();
void setRootObject(QObject *);
void render(bool needsSync);