Results 1 to 4 of 4

Thread: Semi transparent overlay with opaque child widgets

  1. #1
    Join Date
    May 2008
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Semi transparent overlay with opaque child widgets

    Hi All,

    I want to create opaque child widget over semi transparent parent widget.

    If I so setWindowOpacity(.4) parent become transparent and same is propagated to child, I tired with setstylesheet
    Qt Code:
    1. QString qStrStyleSheet(QString(" QDialog {\
    2. background-color: rgba(100,100,100,20%);\
    3. }"));
    4.  
    5. setStyleSheet(qStrStyleSheet);
    To copy to clipboard, switch view to plain text mode 

    but was not able to draw it properly, what I saw was black parent (opaque).

    I also tried using
    Qt Code:
    1. setAttribute(Qt::WA_TranslucentBackground, true);
    2. setWindowFlags(Qt::FramelessWindowHint)
    To copy to clipboard, switch view to plain text mode 
    , this gives exact behavior but parent is transparent, however I want it to be semi-transparent (40%).

    I have also tried overwriting paintEvent
    Qt Code:
    1. QPalette palette;
    2. palette.setColor(backgroundRole(), QColor(194,194,194,40));
    3. setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    After searching in google I came across this link , still it's not working for me.

    I am using Qt-4.6 with windows-7

    Can anyone help me with this.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Semi transparent overlay with opaque child widgets

    Could you post a sample image of how you want?

    Also be aware that a widget and a window are handled differently in this case.

  3. #3
    Join Date
    May 2008
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Semi transparent overlay with opaque child widgets

    Thanks for your prompt reply, this issue is resolved.


    Qt Code:
    1. setAutoFillBackground(false);
    2. setWindowFlags(Qt::FramelessWindowHint);
    3. setAttribute(Qt::WA_TranslucentBackground);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.setRenderHint(QPainter::Antialiasing);
    5. painter.setPen(Qt::NoPen);
    6. painter.setBrush(QColor(100,100,100, 127));
    7.  
    8. painter.drawRect(0, 0, width(), height());
    9. }
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to y.s.bisht for this useful post:

    basania (18th July 2019)

  5. #4
    Join Date
    Mar 2019
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Semi transparent overlay with opaque child widgets

    It's been helpful, thanks!

Similar Threads

  1. How to make overlapping widgets opaque ?
    By ada10 in forum Newbie
    Replies: 3
    Last Post: 9th September 2010, 10:06
  2. Replies: 0
    Last Post: 25th August 2010, 17:39
  3. Semi-Transparent Widgets over OpenGL rendering
    By ddpro in forum Qt Programming
    Replies: 2
    Last Post: 19th August 2010, 01:56
  4. Non-transparent QWidget on semi-transparent parent
    By EuroElessar in forum Qt Programming
    Replies: 0
    Last Post: 29th August 2008, 16:20
  5. qt4.3 semi-transparent widgets winxp
    By kernel_panic in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2007, 06:25

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.