Results 1 to 2 of 2

Thread: Destirantion Image display Trasparentley over Source Image

  1. #1
    Join Date
    Jan 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Destirantion Image display Trasparentley over Source Image

    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

    Qt Code:
    1. void ImageView::OpenImage(QString path)
    2. {
    3.  
    4. QDir currentDir(path);
    5. QStringList files;
    6. files = currentDir.entryList(QStringList("*.jpg"));
    7. for(int i=0;i<files.size();i++)
    8. {
    9.  
    10. QString fileName=path+"/"+files.at(i);
    11. if(i>=2)
    12. break;
    13. images[i].load(fileName);
    14.  
    15. }
    16. m_SrcPixmap=QPixmap::fromImage(images[0]);
    17. m_DestPixmap=QPixmap::fromImage(images[1]);
    18.  
    19. update();
    20. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void ImageView::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter p(this);
    4.  
    5. p.drawPixmap(150,150,m_SrcPixmap.width(),m_SrcPixmap.height(),m_SrcPixmap);
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void ImageView::mouseMoveEvent(QMouseEvent *me)
    2. {
    3. if(me->buttons()==Qt::LeftButton)
    4. {
    5. QPainter painter(&m_SrcPixmap);
    6.  
    7. painter.setCompositionMode(QPainter::CompositionMode_Overlay);
    8. painter.drawPixmap(me->x(),me->y(), m_DestPixmap);
    9.  
    10.  
    11. painter.end();
    12. update();
    13. }
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Destirantion Image display Trasparentley over Source Image

    Try with modified opacity:
    Qt Code:
    1. QPainter painter(&m_SrcPixmap);
    2. painter.setOpacity(0.5);
    3. painter.drawPixmap(me->x(),me->y(), m_DestPixmap);
    4. painter.end();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Qt Image Display...
    By mahe2310 in forum Qt Programming
    Replies: 9
    Last Post: 22nd July 2013, 09:06
  2. image source changes in animation
    By vinayaka in forum Qt Quick
    Replies: 0
    Last Post: 27th September 2011, 08:31
  3. Replies: 1
    Last Post: 24th August 2011, 14:09
  4. Image display
    By bmn in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 13:52
  5. Display image
    By Pesho in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2007, 00:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.