PDA

View Full Version : Semi transparent overlay with opaque child widgets



y.s.bisht
10th November 2011, 16:13
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

QString qStrStyleSheet(QString(" QDialog {\
background-color: rgba(100,100,100,20%);\
}"));

setStyleSheet(qStrStyleSheet);


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

I also tried using


setAttribute(Qt::WA_TranslucentBackground, true);
setWindowFlags(Qt::FramelessWindowHint)
, this gives exact behavior but parent is transparent, however I want it to be semi-transparent (40%).

I have also tried overwriting paintEvent


QPalette palette;
palette.setColor(backgroundRole(), QColor(194,194,194,40));
setPalette(palette);


After searching in google I came across this link (http://gonwan1985.blogspot.com/2009/03/transparency-translucency-in-qt.html?showComment=1268488475782#c129049113326695 0817), still it's not working for me.

I am using Qt-4.6 with windows-7

Can anyone help me with this.

Santosh Reddy
11th November 2011, 04:27
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.

y.s.bisht
11th November 2011, 10:48
Thanks for your prompt reply, this issue is resolved.




setAutoFillBackground(false);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);



void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(100,100,100, 127));

painter.drawRect(0, 0, width(), height());
}

basania
18th July 2019, 10:25
It's been helpful, thanks!