Results 1 to 3 of 3

Thread: Transparent Widgets and alpha blending

  1. #1
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Transparent Widgets and alpha blending

    Hi,
    In my application my main Widget - 'centralWidget' is the child of the main window class, that is its parent isn't a widget but rather the main class of the application.
    I am trying to set 'centralWidget' to be transparent, that is rgba = 0,0,0,0 (alpha blending).
    here is what I have tried:

    centralWidget->setStyleSheet("background: transparent");

    or
    QPalette pal = ui->centralWidget->palette();
    QColor BGcolor(0,0,0,0);
    pal.setColor(ui->centralWidget->backgroundRole(), BGcolor);
    centralWidget->setPalette(pal);
    centralWidget->setAttribute(Qt::WA_NoSystemBackground);


    both make the children of 'centralWidget' transparent but do nothing to 'centralWidget'.

    any leads or ideas will be very appreciated.
    thanks,
    Ido.

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Transparent Widgets and alpha blending

    You have to set attributes in the constructor of your widget

    Qt Code:
    1. setAttribute(Qt::WA_TranslucentBackground,true);
    2. setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
    3. setWindowOpacity(0.5);
    4.  
    5. bool t=testAttribute ( Qt::WA_TranslucentBackground);
    6. qDebug()<<t;
    To copy to clipboard, switch view to plain text mode 

    The Qt::WA_TranslucentBackground is mandatory, the other flags I dont remember if they are, check the Qt documentation. Also, in linux, you have to enable transparency in your X-window system. In my machine, without compiz enabled, it doenst work, but with compiz works fine.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

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

    idoroth (16th October 2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Transparent Widgets and alpha blending

    John, my good man. right on the nail's head.
    Great help.
    Thanks for you time and effort.
    Ido.

Similar Threads

  1. Replies: 0
    Last Post: 8th November 2010, 22:17
  2. Replies: 2
    Last Post: 31st May 2010, 12:57
  3. Replies: 1
    Last Post: 18th September 2009, 11:32
  4. Alpha blending..
    By chethana in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2007, 11:15
  5. Transparent widgets
    By incapacitant in forum Newbie
    Replies: 10
    Last Post: 21st March 2006, 19:01

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.