Results 1 to 3 of 3

Thread: Widget Transparency

  1. #1
    Join Date
    Nov 2011
    Location
    Bangalore
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Widget Transparency

    Hi all....
    I am also having problem with the Transparency...
    I have a parent widget with some background color... And i have two child widgets which i am placing over my parent widget. In this i am placing one child widget over another. And the first child widget which is below the second child should be partially visible means i need my second child widget as semi transparent. I can set the transparency for individual widget. But when i am setting this as a child of another widget i am not able to accomplish that transparency...


    Please help me regarding this.. Here i have a dded one image..On that you can see what i really need.....

    Thanks in advance...
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Widget Transparency

    I remember I had a similar problem in the past and have not found a qt solution. I've managed to achieve transparency only with win32 code:
    Qt Code:
    1. #ifdef Q_OS_WIN32
    2. HWND hwnd = (HWND) winId(); // get handle of the widget
    3. LONG styles = GetWindowLong(hwnd, GWL_EXSTYLE);
    4. SetWindowLong(hwnd, GWL_EXSTYLE, styles | WS_EX_TRANSPARENT);
    5. #else
    To copy to clipboard, switch view to plain text mode 

    After this transparency should work. Big thanks to anybody who can provide a better way to do this.

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget Transparency

    I'm not sure if I understood you right, but if you want your widget background to be transparent it's quite simple:
    Qt Code:
    1. MainWindow::MainWindow( QWidget* p )
    2. :
    3. {
    4. QWidget* w1 = new QWidget( this );
    5. w1->setFixedSize( 100, 100 );
    6. w1->setStyleSheet( "background: rgba(255, 0, 0, 127);" ); // 50% transparent
    7.  
    8. QLabel* l = new QLabel( "test test test1", w1 );
    9. l->move( 0, 80 );
    10. l->setStyleSheet( "background: none;" ); // remove inherited background
    11.  
    12. QWidget* w2 = new QWidget( this );
    13. w2->setFixedSize( 100, 100 );
    14. w2->move( 50, 50 );
    15. w2->setStyleSheet( "background: rgba(0, 255, 0, 127);" ); // 50% transparent
    16.  
    17. w1->show();
    18. w2->show();
    19. }
    To copy to clipboard, switch view to plain text mode 
    This transparency applies only to widget background, so ie button will still be 100% opaque.
    Is that what you needed?
    transparency.png

Similar Threads

  1. About Designer default Widget transparency
    By aguayro in forum Qt Tools
    Replies: 0
    Last Post: 11th March 2012, 21:11
  2. Making a chld widget semi transparent:works ony for full transparency.
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 7th October 2010, 13:03
  3. Top Level Widget Transparency
    By dotboy in forum Qt Programming
    Replies: 9
    Last Post: 2nd July 2009, 13:11
  4. Transparency ... Again
    By EricF in forum Qt Programming
    Replies: 4
    Last Post: 1st December 2007, 19:52
  5. transparency
    By roms18 in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 19:38

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.