Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A qt widget with fully transparent background

I need to create a qt widget, which will act as a parent for some other widgets, and which will order them.

Now, the question is how do I make it's background fully transparent?

I thought to do it like this :

struct Imp
{
  Imp( QWidget *parent ) : thisWidget( new QWidget( parent ) )
  {
    thisWidget->setAttribute( Qt::WA_TranslucentBackground, true );
  }

  QWidget *thisWidget;
};

Do you think that I need to set the attribute, or is it going to work fine without it?

like image 407
BЈовић Avatar asked Nov 25 '10 15:11

BЈовић


People also ask

What is widget transparency?

Every widget type has an optional setting called opacity: which you can use to set the opacity of that widget. This is a value from 0.0 to 1.0, with 0 meaning 0% opacity (completely transparent and not visible at all), 1.0 meaning 100% opacity (the default), 0.25 meaning 25%, etc.


1 Answers

By default in Qt4, a QWidget will draw nothing for its own background, and only its children will be drawn. If you want to override that, you specifically have to tell the widget to draw its background via one of its properties. Note that some widgets derived from QWidget will automatically draw backgrounds.

like image 177
Caleb Huitt - cjhuitt Avatar answered Nov 16 '22 00:11

Caleb Huitt - cjhuitt