Results 1 to 5 of 5

Thread: QPainter::setCompositingMode without effect

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QPainter::setCompositingMode without effect

    Hi!

    I am developping my own QGraphicsItem that should paint a partly transparent QImage. This is easy, it can just be realised via

    Qt Code:
    1. void GraphicsHairstyleItem::paint(QPainter *painter,
    2. const QStyleOptionGraphicsItem *option, QWidget *widget)
    3. {
    4. Q_UNUSED(option);
    5. Q_UNUSED(widget);
    6.  
    7. painter->drawImage(m_imgrect, m_img_warped);
    8. }
    To copy to clipboard, switch view to plain text mode 

    OK. But now I qould like to be able to realise something like "erasing", or like the rubber-tool in Photoshop. Therefor I inted to have a second QImage called the "cutmask" that is transparent everywhere except for parts of the image that should be erased.

    Following the documentation on Compositing modes, if the image to be shown is the destination and the cutmask acts as the source (but I'm not a 100% sure about this), then QPainter::CompositionMode_DestinationOut should do the right thing.

    This means that only portions of the image where the cutmask is transparent are shown.

    So my code looks like

    Qt Code:
    1. void GraphicsHairstyleItem::paint(QPainter *painter,
    2. const QStyleOptionGraphicsItem *option, QWidget *widget)
    3. {
    4. Q_UNUSED(option);
    5. Q_UNUSED(widget);
    6.  
    7. painter->drawImage(m_imgrect, m_img_warped);
    8. painter->setCompositionMode(QPainter::CompositionMode_DestinationOut);
    9. painter->drawImage(m_imgrect, m_img_cutmask);
    10. }
    To copy to clipboard, switch view to plain text mode 

    see the attachments for my cutmask image "cut.png".

    But in this realisation (and also in many others), the white spot is just drawn on top of the image, instead of erasing it out there.

    Thank you very much for your help in advance,
    Olli
    Attached Images Attached Images
    Last edited by olidem; 4th March 2009 at 20:10. Reason: reformatted to look better

Similar Threads

  1. QPushButton fade effect without animation
    By Kostanev in forum Qt Programming
    Replies: 11
    Last Post: 12th November 2008, 09:46
  2. Screen Resolution stting takes effect on application !
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2008, 13:06
  3. QFont::setPointSize() does not take effect
    By lovelypp in forum Qt Programming
    Replies: 5
    Last Post: 14th July 2008, 19:44
  4. QImage glow effect
    By MarkoSan in forum Qt Programming
    Replies: 4
    Last Post: 31st March 2008, 06:15
  5. Designing a "slide-out" effect
    By Gray in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2007, 10:52

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.