PDA

View Full Version : Destirantion Image display Trasparentley over Source Image



wizards2020
18th January 2012, 08:11
Hello,

I want to display Destination image transparently (about 50%) over displayed source image. I did in the following way, but I am not able to achieve.

I read two images and prepared QPixmaps for those two. I displayed first image on the screen and on MouseMoveEvent I am writing second image over first.

Can anyone help me how to display an image transparently over another?

Thanks
Wizards


void ImageView::OpenImage(QString path)
{

QDir currentDir(path);
QStringList files;
files = currentDir.entryList(QStringList("*.jpg"));
for(int i=0;i<files.size();i++)
{

QString fileName=path+"/"+files.at(i);
if(i>=2)
break;
images[i].load(fileName);

}
m_SrcPixmap=QPixmap::fromImage(images[0]);
m_DestPixmap=QPixmap::fromImage(images[1]);

update();
}


void ImageView::paintEvent(QPaintEvent *event)
{
QPainter p(this);

p.drawPixmap(150,150,m_SrcPixmap.width(),m_SrcPixm ap.height(),m_SrcPixmap);

}


void ImageView::mouseMoveEvent(QMouseEvent *me)
{
if(me->buttons()==Qt::LeftButton)
{
QPainter painter(&m_SrcPixmap);

painter.setCompositionMode(QPainter::CompositionMo de_Overlay);
painter.drawPixmap(me->x(),me->y(), m_DestPixmap);


painter.end();
update();
}

}

stampede
18th January 2012, 10:00
Try with modified opacity:


QPainter painter(&m_SrcPixmap);
painter.setOpacity(0.5);
painter.drawPixmap(me->x(),me->y(), m_DestPixmap);
painter.end();