fix QWidget::grab(QRect(x, y, -1, -1))

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 <Friedemann.Kleint@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Joerg Bornemann 2012-07-02 17:08:43 +02:00 committed by Qt by Nokia
parent 3037525530
commit 97b8915bb1

View File

@ -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();