Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make QT Widgets semi-opaque

I am working with a QWidget elements which contains child elements, what I need is some way to make this widget semi transparent, completely, including its childs.

I have seen a method for QWidgets which is QWidget::setWindowOpacity() but this works only if the widget is a window itself, and in my case this widget is part of a layout.

The goal of all this, is me being able to make this widget fade when appearing or disappearing.

Thanks for any ideas, hopefully not making a custom widget, but if there is no more alternatives, I can do it anyway.

like image 300
Ale Avatar asked Sep 15 '11 19:09

Ale


1 Answers

You can use QGraphicsOpacityEffect.

A sample code fragment for 50% transparency would be:

ui->setupUi(this);
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect(ui->pushButton);
effect->setOpacity(0.5);
ui->pushButton->setGraphicsEffect(effect);
like image 109
lemoran Avatar answered Sep 28 '22 15:09

lemoran