Results 1 to 4 of 4

Thread: QGraphicsItem Opacity Mask

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsItem Opacity Mask

    Does anyone know of a way to apply an opacity mask to a QGraphicsItem and it's children? Basically I'm looking to define per-pixel opacity like a bitmap's alpha channel. The feature looks like it will be available in Qt 4.6 via QGraphicsOpacityEffect, but I'm wondering if anyone knows of a solution for Qt 4.5.2.

    Thanks!

    Scott

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem Opacity Mask

    If you mean an arbitrary item then I don't think it is possible. If you mean for your own items then by overriding mouse events and reimplementing the paint routine you should be able to do appropriate masking.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    sdanahy (30th September 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem Opacity Mask

    There is opacity features fo QGraphicsitem but with same opacity for all pixels. Not per-pixel defined.
    You can can play with QGraphicsItem::opaqueArea to define a mask independtly of opacity.

    I can't see any solution without overloading the paintEvent, draw into a QPixmap and defined you per-pixel opacity mask with alpha channel.

    What is the goal of your need? Maybe another design cans take benefits of Qt features.

  5. The following user says thank you to scascio for this useful post:

    sdanahy (30th September 2009)

  6. #4
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem Opacity Mask

    Thanks to both of you for the response.

    All of the items in the view are mine, but the problem with just overriding the paint routine is that I want the mask to apply to the item's children as well (which are drawn after the item, if I understand correctly). I could propagate the opacity mask down the display tree, but then every item in my view would need a custom paint routine that would apply the mask. That seems awfully cumbersome so I was looking for a better way.

    Thanks again for the ideas...

    Scott

Similar Threads

  1. QLineEdit and input mask
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 9th May 2014, 19:47
  2. Replies: 2
    Last Post: 25th March 2011, 09:18
  3. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  4. input mask problem
    By zgulser in forum Qt Programming
    Replies: 10
    Last Post: 8th May 2009, 14:11
  5. Replies: 1
    Last Post: 25th February 2009, 00:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.