From 97b8915bb122c6f4160cb1ed05c35a1ad95f783f Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 2 Jul 2012 17:08:43 +0200 Subject: fix QWidget::grab(QRect(x, y, -1, -1)) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Grabbing a widget with a position != (0,0) and an invalid size returned a pixmap of the widget's size. As we're grabbing just a part of the widget, the pixmap must be smaller by the amount of x, respective y. Autotest: tst_QWidget::grab() Change-Id: I3d5103e6e7c042cc6112038ace236e3f69060bda Reviewed-by: Friedemann Kleint Reviewed-by: Samuel Rødal --- src/widgets/kernel/qwidget.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 0da28416a3..2fcf3e457c 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -4763,8 +4763,12 @@ QPixmap QWidget::grab(const QRect &rectangle) const QWidget::RenderFlags renderFlags = QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask; QRect r(rectangle); - if (r.width() < 0 || r.height() < 0) + if (r.width() < 0 || r.height() < 0) { + // For grabbing widgets that haven't been shown yet, + // we trigger the layouting mechanism to determine the widget's size. r = d->prepareToRender(QRegion(), renderFlags).boundingRect(); + r.setTopLeft(rectangle.topLeft()); + } if (!r.intersects(rect())) return QPixmap(); -- cgit v1.2.3