1 Attachment(s)
transparency problem. pls help.
Here's my codes.
Attached is the result of the image.
You can see that the parts that are transparent ends up with black color.
What gives? I like it to be the background color of whatever that is underneath this rainbow drawing. How do I do that?
Many thanks!
Code:
mypainter->setPen(Qt::NoPen);
rect_gradient.setColorAt(0, Qt::red);
rect_gradient.setColorAt(.17, Qt::yellow);
rect_gradient.setColorAt(.33, Qt::green);
rect_gradient.setColorAt(.50, Qt::cyan);
rect_gradient.setColorAt(.66, Qt::blue);
rect_gradient.setColorAt(.81, Qt::magenta);
rect_gradient.setColorAt(1, Qt::red);
mypainter->setBrush(rect_gradient);
mypainter->drawRect(width() / 2, 0, width() / 2, height());
alpha_gradient.setColorAt(0, Qt::white);
alpha_gradient.setColorAt(0.2, Qt::white);
alpha_gradient.setColorAt(0.5, Qt::transparent);
alpha_gradient.setColorAt(0.8, Qt::white);
alpha_gradient.setColorAt(1, Qt::white);
mypainter
->setCompositionMode
(QPainter::CompositionMode_DestinationIn);
mypainter->setBrush(alpha_gradient);
mypainter->drawRect(0, 0, width(), height());
mypainter
->setCompositionMode
(QPainter::CompositionMode_DestinationOver);
mypainter->setPen(Qt::NoPen);
mypainter
->setRenderHint
(QPainter::SmoothPixmapTransform);
Re: transparency problem. pls help.
Hi,
see QWidget::setAutoFillBackground(). Also have a look at the windget attribute Qt::WA_NoSystemBackground.
Re: transparency problem. pls help.
I tried that actually. They seem to have no effect over the results I'm getting. :(
Any clue??
Re: transparency problem. pls help.
Could someone please help me on this?
I've tried all kind of compostion mode and the suggestions. None of them work.
And I've been stuck on this for hours and hours. A seemingly simple task of drawing a partial transparent stuff yet it seems impossible to do...
Re: transparency problem. pls help.
Ehm, yes, why do you alter the composition mode?
Code:
#include <QtGui>
{
public:
{
}
protected:
{
mypainter.fillRect(0, 0, width(), height(), Qt::transparent);
mypainter.setPen(Qt::NoPen);
rect_gradient.setColorAt(0, Qt::red);
rect_gradient.setColorAt(.17, Qt::yellow);
rect_gradient.setColorAt(.33, Qt::green);
rect_gradient.setColorAt(.50, Qt::cyan);
rect_gradient.setColorAt(.66, Qt::blue);
rect_gradient.setColorAt(.81, Qt::magenta);
rect_gradient.setColorAt(1, Qt::red);
mypainter.setBrush(rect_gradient);
mypainter.drawRect(width() / 2, 0, width() / 2, height());
alpha_gradient.setColorAt(0, Qt::white);
alpha_gradient.setColorAt(0.2, Qt::white);
alpha_gradient.setColorAt(0.5, Qt::transparent);
alpha_gradient.setColorAt(0.8, Qt::white);
alpha_gradient.setColorAt(1, Qt::white);
// mypainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
mypainter.setBrush(alpha_gradient);
mypainter.drawRect(0, 0, width(), height());
mypainter.
setCompositionMode(QPainter::CompositionMode_DestinationOver);
mypainter.setPen(Qt::NoPen);
mypainter.
setRenderHint(QPainter::SmoothPixmapTransform);
}
};
int main(int argc, char* argv[])
{
parent.
setBackgroundRole(QPalette::ToolTipBase);
test t(&parent);
parent.show();
return a.exec();
}
1 Attachment(s)
Re: transparency problem. pls help.
Thanks. I comment out the codes you suggested.
and ended up with the attached picture.
It still does not make sense 'cause the transparent part should be
somewhere in the middle of the picture since that's where I
set the 'transparent'. yet in the picture, it is the right side that
seems to be getting the transparent. Beats me!? I just cant figure
out...
thank you for any pointer.
Re: transparency problem. pls help.
? no it is white at left and right. Only in the middle it is transparent:
Code:
alpha_gradient.setColorAt(0.5, Qt::transparent);
And keep in mind, you are drawing with a transparent pen, you are not making all pixel in that area transparent.
1 Attachment(s)
Re: transparency problem. pls help.
Sorry. I must be missing something terribly...
The expected results I thought I should get is as shown in the attached file.
(ignore the checkboard patten in the background. main idea is the transparency, where does it start)
So, this expected result has the transparency starts from the middle of the window and then slowly goes back to the "rainbow" color. But the actual result, after commenting out the code you suggested ends up the opposite.
I really dont get it. What really am I wrong in understanding what I should get?
Thanks once again.
Re: transparency problem. pls help.
Well for that you have to cache the result in a pixmap or image:
Code:
#include <QtGui>
{
public:
{
}
protected:
{
pix.fill(Qt::transparent);
mypainter.setPen(Qt::NoPen);
alpha_gradient.setColorAt(0, Qt::white);
alpha_gradient.setColorAt(0.2, Qt::white);
alpha_gradient.setColorAt(0.5, Qt::transparent);
alpha_gradient.setColorAt(0.8, Qt::white);
alpha_gradient.setColorAt(1, Qt::white);
mypainter.setBrush(alpha_gradient);
mypainter.drawRect(0, 0, width(), height());
mypainter.
setCompositionMode(QPainter::CompositionMode_SourceIn);
rect_gradient.setColorAt(0, Qt::red);
rect_gradient.setColorAt(.17, Qt::yellow);
rect_gradient.setColorAt(.33, Qt::green);
rect_gradient.setColorAt(.50, Qt::cyan);
rect_gradient.setColorAt(.66, Qt::blue);
rect_gradient.setColorAt(.81, Qt::magenta);
rect_gradient.setColorAt(1, Qt::red);
mypainter.setBrush(rect_gradient);
mypainter.drawRect(width() / 2, 0, width() / 2, height());
p.drawPixmap(0,0,pix);
}
};
int main(int argc, char* argv[])
{
parent.
setBackgroundRole(QPalette::ToolTipBase);
test t(&parent);
parent.show();
return a.exec();
}
Re: transparency problem. pls help.
You are the man!!! THANK YOU!!