PDA

View Full Version : changing transparency of part of a qgraphicspixmap item



knapshots
2nd June 2011, 16:40
Guys,

i tried using qlinear gradient as the opacity mask for qgraphicsopacityeffect on a qgraphicspixmap item to change the transparency of certain region of the item like this


/*******CODE STARTS
//expose is the name of the qgraphicsopacityeffect variable
//theRect defines the area where the opacity has to be changed
// setGraphicsEffect(expose); has already been done

QLinearGradient* theDude= new QLinearGradient(theRect.topLeft(),theRect.bottomRi ght();



theDude->setColorAt(0,Qt::transparent);
theDude->setColorAt(1.0,Qt::white);
expose->setOpacityMask(*theDude);


delete theDude;
*************CODE ENDS******************************/


but this code always ends up changing only the bottom right of the qgraphicspixmapitem no matter which rectangle is passed...
where am i goin wrong... and in general, how do u change transparency of part of
a qgraphicspixmapitem and leave the rest of the area unaffected;

knapshots
3rd June 2011, 11:25
well, got the sol folks after some hrs of trial and error.... hope it can help someone out
in the future.....

QPainter* thePainter= new QPainter(&currentImage);

thePainter->setOpacity(0.4);
//pos is ur items pos.....
thePainter->fillRect(theRect.topLeft().x()-pos().x(),theRect.topLeft().y()-pos().y(),theRect.width(),theRect.height(),Qt::bla ck);


setPixmap(QPixmap::fromImage(currentImage));

delete thePainter;