Results 1 to 4 of 4

Thread: How to enable transparency (composition) of QGraphicsItems

  1. #1
    Join Date
    Apr 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to enable transparency (composition) of QGraphicsItems

    Hello

    First of all, greetings to everybody since I am new in the forum.

    I have a question on how to enable composition of QGraphicsItems.

    In my QGraphicsScene I paint several QGraphicsItems that the user can then drag around. If one item is dragged over another I would like to be able to see the one in the background through the one that is being dragged (and is in the foreground). I guess I should somehow enable composition. I got this working if the two items were rendered on top of a QPixmap, but I do not know how to do it if I am rendering on a QGraphicsScene.

    Does the z value of the items in the scene also play a role?

    I would appreciate any help on this.

  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: How to enable transparency (composition) of QGraphicsItems

    You don't have to enable anything. You only need to use colours that are not fully opaque (with alpha values less than max). In case of pixmaps you'll have to set some masks on them (unless they already have them).

  3. #3
    Join Date
    Apr 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to enable transparency (composition) of QGraphicsItems

    Thanks a lot, it worked.

    Just one more question: how do you set the alpha channel of a QImage? If for instance I create a QImage from let's say a TIFF file, how can I then set its alpha value?

  4. #4
    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: How to enable transparency (composition) of QGraphicsItems


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

    aarpon (7th April 2009)

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.