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
) {
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::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();
}
To copy to clipboard, switch view to plain text mode
{
p.drawPixmap(150,150,m_SrcPixmap.width(),m_SrcPixmap.height(),m_SrcPixmap);
}
void ImageView::paintEvent(QPaintEvent *event)
{
QPainter p(this);
p.drawPixmap(150,150,m_SrcPixmap.width(),m_SrcPixmap.height(),m_SrcPixmap);
}
To copy to clipboard, switch view to plain text mode
{
if(me->buttons()==Qt::LeftButton)
{
painter.
setCompositionMode(QPainter::CompositionMode_Overlay);
painter.drawPixmap(me->x(),me->y(), m_DestPixmap);
painter.end();
update();
}
}
void ImageView::mouseMoveEvent(QMouseEvent *me)
{
if(me->buttons()==Qt::LeftButton)
{
QPainter painter(&m_SrcPixmap);
painter.setCompositionMode(QPainter::CompositionMode_Overlay);
painter.drawPixmap(me->x(),me->y(), m_DestPixmap);
painter.end();
update();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks