Skip to content

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 Pick-to: 6.3 6.2 5.15 Reviewed-by: Volker Hilsheimer volker.hilsheimer@qt.io (cherry picked from commit b20cf7fe)

Merge request reports