Results 1 to 3 of 3

Thread: Paintevent and transparent children

  1. #1
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Paintevent and transparent children

    Hi guys !
    I'm facing a problem right now, and I don't find any solution, or ever subject who can help me to resolve it. If you know Flash, or AfterEffect, I try to do a Timeline like the one you can found in theses software.

    First of all, all my classes inherits QWidget.
    Now I have a class I use to make the background : Line. To do that, I use the paintEvent method to draw the background, and the borders.
    Next, I have a class, that I call Key (to make it simple, a QPixmap in a QLabel). The fact is that a Line contains some Keys, placed in function of a value. So all Keys are children of a Line.

    The problem came when the keys have some transparent part in them. Like you can see in the image in attachment, my Key pixmap is a transparent square with a black circle in the middle. And in the transparent part, where I should have the white of the Line behind him, I see the classic background that all my widgets have.

    What I understand is that the paintEvent don't draw behind the widget children, is there any way to force it ?

    I looked in the flags, but don't find my pleasure.

    I am open to any suggestion, thanks a lot for any help you can provide !
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Paintevent and transparent children

    See widget attribute Qt::WA_TranslucentBackground
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Paintevent and transparent children

    Well, I tried this, and it doesn't works. The problem came from the fact that the widget doesn't know which region is transparent, and don't redraw under transparent pixels.
    But, just know, I thought about one thinks, and the documentation gave me the answer. You can define a mask over your widget, for case like this.
    The solution was really simple with this :
    myWidget.setPixmap(pixmap)
    myWidget.setMask(pixmap.mask())

Similar Threads

  1. Replies: 2
    Last Post: 31st May 2010, 11:57
  2. Non-transparent QWidget on semi-transparent parent
    By EuroElessar in forum Qt Programming
    Replies: 0
    Last Post: 29th August 2008, 16:20
  3. Replies: 2
    Last Post: 19th August 2008, 09:46
  4. Transparent background on QLabel on transparent QWidget
    By codeslicer in forum Qt Programming
    Replies: 1
    Last Post: 13th February 2008, 02:10
  5. children()
    By vermarajeev in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2007, 15:15

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.