Search code examples
c++qtqt5qpainterqpixmap

How to draw darkened QPixmap?


I'm looking for a fast and effective way to draw a QPixmap with QPainter, but have the pixmap appear darker then normal. Is there some sort of filter or effect that can be applied to either the QPixmap or QPainter while drawing to create this effect?


Solution

  • Some of the earlier comments will leave a dark gray rectangle on your screen. Using the composition mode, will darken everything visible, yet leaving any transparent areas still transparent.

    painter.setCompositionMode (QPainter::CompositionMode_DestinationIn);
    painter.fillRect (rect, QBrush (QColor (0,0,0,128)));