Results 1 to 9 of 9

Thread: Translucent Qt widget

  1. #1
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Translucent Qt widget

    I am developing an application for Embedded Linux using Qt 4.6.2 where we need to display video along with UI. UI may have a hole along with other UI objects on screen where user can see the video displayed in background.

    I apply following attributes to every widget in my application:
    Qt Code:
    1. widget->setAttribute(Qt::WA_NoMousePropagation);
    2. widget->setAutoFillBackground(true);
    3. //widget->setAttribute(Qt::WA_OpaquePaintEvent);
    4. widget->setAttribute(Qt::WA_PaintOnScreen);
    To copy to clipboard, switch view to plain text mode 

    I use the following method to create a hole in UI at required place:

    Qt Code:
    1. void DVRGlobal::createHole(QWidget *widget)
    2. {
    3. if(widget==NULL)
    4. return;
    5. QWidget *parentWidget = widget;
    6. //Find out parent most widget
    7. while(parentWidget->parentWidget()!=NULL)
    8. parentWidget = parentWidget->parentWidget();
    9.  
    10. parentWidget->setAttribute(Qt::WA_TranslucentBackground);
    11. if(parentWidget!=widget)
    12. widget->setStyleSheet("background:transparent");
    13. }
    To copy to clipboard, switch view to plain text mode 

    This works with following two problems:
    (1) Translucent widget does not repaint itself and I only see the background until I hide/show the complete widget, and it is very slow too.
    (2) Any child widget on translucent widget does not repaint itself. i.e. when tool tip disappears on any widget, the background area is not repainted and remains black.
    Last edited by manojmka; 9th July 2010 at 12:47.

  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: Translucent Qt widget

    I think for playing video with overlay at a proper framerare you have to do some more tricks like having a graphics chip with two framebuffers: Decode video in one framebuffer, have the Qt ui in the other and let the graphics chip do the compositing.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Translucent Qt widget

    I finally got it working with help of attributes like WA_PaintOnScreen and setAutofillBackground(true), thereafter I define a transparent color key in my system and fill widget with the same. It works very nice and fast.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent Qt widget

    Can you share the final code ?
    It might be useful for others out here..

  5. #5
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Translucent Qt widget

    sure, I have following code for this purpose:

    Qt Code:
    1. void Global::applyAttributes(QWidget *widget)
    2. {
    3. if(widget==NULL)
    4. return;
    5.  
    6. widget->setAttribute(Qt::WA_NoMousePropagation);
    7. widget->setAutoFillBackground(true);
    8. //widget->setAttribute(Qt::WA_OpaquePaintEvent);
    9. widget->setAttribute(Qt::WA_PaintOnScreen);
    10.  
    11. foreach(QObject *child,widget->children())
    12. {
    13. if(child->isWidgetType())
    14. applyAttributes((QWidget*)child);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    I call applyAttributes method on parentMost widget in my application and thus every widget is set with WA_PaintOnScreen and autoFillBackground attributes.

    Qt Code:
    1. void lobal::createHole(QWidget *widget)
    2. {
    3. if(widget==NULL)
    4. return;
    5.  
    6. widget->setBackgroundRole(QPalette::Window);
    7. QPalette transparentPal;
    8. transparentPal.setColor(QPalette::Window, QColor(128,64,128));
    9. widget->setPalette(transparentPal);
    10. }
    To copy to clipboard, switch view to plain text mode 

    I call createHole() on the widget which needs to be transparent to show video. Above mentioned color key (128,64,128) can be any color which is our internal fbset color to make a transparent layer.

  6. The following user says thank you to manojmka for this useful post:

    giowck (18th July 2010)

  7. #6
    Join Date
    Jan 2012
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Translucent Qt widget

    A few questions comments about this

    1 - I don't think the recursive applyAttributes is needed. If you set a solid background color for your widget and use that as a chroma key (transparent value) and set setAutoFillBackground(true); for just the one widget you want the hole in you should get the same results. You could even just fillRect of that chroma key into the widget as well.

    2 - There are a few problems with this common approach
    a - The chroma key you choose, no matter what it is, will be found someplace else on the UI if you have other images/gradients/etc. which will then show up funny once you set the key.
    b - There is no way to alpha-composite on top of the widget, i.e. any rendering controls, etc. which are children of the widget are alpha-blended to the widget's background, but then that isn't alpha-blended to the video showing in the background video plane, so it shows up solid.

    Question is: How do you solve those problems!

  8. #7
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Translucent Qt widget

    correct omnilala,

    for the same reasons I am not using the approach you mentioned and using the one which I mentioned.

  9. #8
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent Qt widget

    transparentPal.setColor(QPalette::Window, QColor(128,64,128)); <-- when you have this color code, how can you tell your program to make this color translucent?

  10. #9
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Translucent Qt widget

    That is a frame buffer set color key.

Similar Threads

  1. translucent background (on Gnome)
    By drus in forum Qt Programming
    Replies: 0
    Last Post: 31st May 2010, 09:23
  2. QT Quarterly 29 - Translucent Widgets
    By PLan2010 in forum Newbie
    Replies: 0
    Last Post: 17th May 2010, 10:32
  3. Have translucent window follow mouse
    By mike_am_i in forum Qt Programming
    Replies: 2
    Last Post: 27th October 2009, 11:18
  4. Translucent window background in 4.3.2 - possible?
    By dpimka in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2009, 09:53
  5. Opague/Transparent/translucent
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2008, 21:56

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.