diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-02-24 01:10:43 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-25 12:29:34 +0000 |
commit | ad3e4d109779beff8cdd2d62bf11262f964aebad (patch) | |
tree | 61437546f46af2bf33aa65766f1b7fe326ec27e8 /src | |
parent | e415366b6e058b02606e17b46e2bd8180674f9a4 (diff) |
QLabel::setPixmap(): remove the no-op self-masking
When calling QLabel::setPixmap() with a 1bpp pixmap (i.e. a bitmap), and
that pixmap didn't have a mask set, QLabel would then set the pixmap as
its own mask.
This seems to be a no-op due to how QPixmap::setMask is coded:
void QPixmap::setMask(const QBitmap &mask) {
// ...
if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask
return;
}
Moreover, in order to convert the pixmap to a QBitmap, the code would just
straight downcast it, triggering UB (if the input to setPixmap wasn't a
QBitmap to begin with).
I *guess* this was done this way to avoid a QBitmap::fromPixmap call,
which however is not expensive at all if the pixmap is already 1bpp,
which QLabel::setPixmap checks explicitly (before attempting to mask the
pixmap). I don't know the historical reasons for the code to have the
shape it had (and the code history is from before open governance).
So get two birds with one stone: remove the no-op and also the UB.
Change-Id: Ibab20492c2945bd1d01f98a18b168fabc56292b0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit b20cf7feee6413a40a69c9e41544d44c53ee6877)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/widgets/qlabel.cpp | 3 |
1 files changed, 0 insertions, 3 deletions
diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index 9b13cfcb9b..997df9d992 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -378,9 +378,6 @@ void QLabel::setPixmap(const QPixmap &pixmap) d->pixmap = new QPixmap(pixmap); } - if (d->pixmap->depth() == 1 && !d->pixmap->mask()) - d->pixmap->setMask(*((QBitmap *)d->pixmap)); - d->updateLabel(); } |