PDA

View Full Version : Painter opacity problem



krisztiantobias
22nd August 2012, 11:10
My code is:


QPainter painter(this);
painter.setOpacity(opacity/255.0);
painter.setBrush(QColor(0,0,0));
painter.save();
painter.setPen(QPen(QBrush(QColor(0,0,0)), 5, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
double meret = 60.0;
painter.drawArc(QRectF(-meret, -meret, meret*2, meret*2),0*16,360*16);
painter.restore();
painter.setPen(Qt::NoPen);
painter.drawRect(QRectF(-5, -meret, 10, meret*2));

The end result is:
8140

But I want this:
8141

How can I do that with drawArc and drawRect?

spirit
22nd August 2012, 11:43
I'm not sure what value in opacity, but you saw this, right?


The value should be in the range 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is fully opaque.

krisztiantobias
22nd August 2012, 13:09
0 to 255. But isn't that the problem. The problem is the next shortly:

Without opacity (painter.setOpacity(220/255.0);) is perfect:
http://img163.imageshack.us/img163/93/nvtelen1l.jpg

But I used opacity:
http://img827.imageshack.us/img827/2788/nvtelen2w.jpg

I would like to this (Photoshop):
http://img339.imageshack.us/img339/4122/nvtelen3.jpg

So if you add opacity to the first picture (like in photoshop and if the 3 layers (3 Ellipse) are rasterized), the result is the third picture, but in Qt the result is the second (like in photoshop and the 3 layers are not rasterized).
How can I get the third picture, if I use the first and I add to it opacity after the drawing?

spirit
22nd August 2012, 15:41
I see. (Misslooked intersection in your first post). Qt's QPainter works correct. For your goal you need to apply opacity to whole scene. In this case you;d probably need to render scene into some buffer, QPixmap or QImage and then render it with needed opacity.
You can also play with Composition modes (http://qt-project.org/doc/qt-4.8/qpainter.html#composition-modes)...