Reputation: 1305
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?
Upvotes: 3
Views: 1495
Reputation: 61
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)));
Upvotes: 2
Reputation: 49329
You don't have pixel access in QPixmap
, so going over the pixels and darkening them is out of the question.
You can however fill a pixmap with a transparent black brush, and use a number of composition modes to further customize the result.
QPainter painter(this);
QPixmap pm("d:/test.jpg");
painter.drawPixmap(QRect(0, 0, 400, 200), pm);
painter.translate(0, 200);
painter.drawPixmap(QRect(0, 0, 400, 200), pm);
painter.fillRect(QRect(0, 0, 400, 200), QBrush(QColor(0, 0, 0, 200)));
Upvotes: 6