[SOLVED]Semi transparent widget
-
I'm trying to implement a semitransparent widget. How should I make this? I've try with setWindowOpacity but didn'work. This is my code:
@#include<QApplication>
#include <QtGui>class ChildWidget : public QLabel
{
public:
ChildWidget( QWidget* parent = 0 ) : QLabel( parent )
{
setWindowOpacity( 0.5 );
setStyleSheet( " background-color:blue " );
}
};class ParentWidget : public QLabel
{
private:
ChildWidget* childWidget;
public:
ParentWidget( QWidget* parent = 0 ) : QLabel( parent )
{
setStyleSheet( " background-color:red " );
setFixedSize( 200, 200 );
childWidget = new ChildWidget( this );
childWidget->setGeometry( 0,0,100,200);
}
};int main( int argc, char* argv[] )
{
QApplication a(argc, argv);
ParentWidget* parentWidget = new ParentWidget;
parentWidget->show();return a.exec();
}@ -
change things to this:
@
ChildWidget( QWidget* parent = 0 ) : QLabel( parent ) { QPalette pal = palette(); pal.setBrush(QPalette::Window, QColor(0, 0, 255, 128) ); setPalette(pal); setAutoFillBackground(true); } ParentWidget( QWidget* parent = 0 ) : QLabel( parent ) { QPalette pal = palette(); pal.setBrush(QPalette::Window, Qt::red); setPalette(pal); setFixedSize( 200, 200 ); setText("asdfa fladsf ldasfjdasfl asdflja sfljdsalfj"); childWidget = new ChildWidget( this ); childWidget->setGeometry( 0,0,100,200); }
@
Although this does not create a full red with a light blue on top. Since the transparency adds the red of the parent widget to the blue of the child widget the resulting color is kind of purple/violet.