From acc1a2bd5520369c690c2769f067aec6bfd869f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 3 Nov 2010 12:10:01 +0100 Subject: Fixed grabWidget sometimes returning uninitialized memory. Use a QImage initialized with transparent to prevent any translucent parts of the widget to end up as garbage, and to ensure that the resulting QPixmap ends up with an alpha format only when needed. Task-number: QTBUG-14945 Reviewed-by: Kim --- src/gui/image/qpixmap.cpp | 5 +++-- tests/auto/qpixmap/tst_qpixmap.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 64d8ed2..290c0f0 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -1101,10 +1101,11 @@ QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) if (!r.intersects(widget->rect())) return QPixmap(); - QPixmap res(r.size()); + QImage res(r.size(), QImage::Format_ARGB32_Premultiplied); + res.fill(0); widget->d_func()->render(&res, QPoint(), r, QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask, true); - return res; + return QPixmap::fromImage(res); } /*! diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index fdf8311..a733d56 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -817,7 +817,7 @@ void tst_QPixmap::grabWidget() for (int row = 0; row < image.height(); ++row) { QRgb *line = reinterpret_cast(image.scanLine(row)); for (int col = 0; col < image.width(); ++col) - line[col] = qRgb(rand() & 255, row, col); + line[col] = qRgba(rand() & 255, row, col, 127); } QPalette pal = widget.palette(); -- cgit v0.12