Ale
Ale

Reputation: 260

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.

Upvotes: 15

Views: 8901

Answers (1)

lemoran
lemoran

Reputation: 538

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);

Upvotes: 39

Related Questions