Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set the opacity of qt widgets?

I know that there is a function QWidget::setWindowOpacity(qreal level) but as written in the documentation this does only work for windows.

Is there a way to make widgets that are lying inside layouts opaque too?

What I'm trying to do is an animation where widgets are fading in. I once did that with a preferences-dialog and there it worked.

So do you think there is a way or a work-around to achieve opacity for widgets inside layouts? How would you do that?

Thanks in advance!

like image 747
Exa Avatar asked Dec 21 '10 13:12

Exa


2 Answers

Just use QGraphicsOpacityEffect in order to achieve this effect.

  • Qt4: http://doc.qt.io/qt-4.8/qgraphicsopacityeffect.html
  • Qt5: http://doc.qt.io/qt-5/qgraphicsopacityeffect.html
like image 83
Miguel Fuentes Avatar answered Sep 22 '22 00:09

Miguel Fuentes


Well for widgets inside mainwidow appear to have setAutoFillBackground(False) by default.

to make it fade in fadeout u need to to use QGraphicsOpacityEffect along with setAutoFillBackground(True)

a small example: write inside the widget which is called inside the mainwindow

op=QGraphicsOpacityEffect(self)
op.setOpacity(1.00) #0 to 1 will cause the fade effect to kick in
self.setGraphicsEffect(op)
self.setAutoFillBackground(True)
like image 30
Ja8zyjits Avatar answered Sep 20 '22 00:09

Ja8zyjits