Qt opacity color brush?
Question
Particular in my case, I want to paint a line to a QGraphicsScene using adLine(). Befor that I have paint something on the scene and I want the last big line on the top of all of these but i still can see what I already paint.
In general, can I paint an Item and fill it with that kind of color which I can see what under the Item?
I have read some thing about BGMode here: http://doc.qt.io/qt-5/qt.html#BGMode-enum but I not sure how it work.
Solution
When you call addLine
, you pass in a QPen
. If you want that pen to draw with a semi-transparent color (so that things "beneath" still show), initialize that QPen
with a color with an alpha-channel value below 255. (See QColor.)
QPen transRed(QColor(0xFF, 0, 0, 0x80));
scene.addLine(x1,y1, x2,y2, transRed);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow