PDA

View Full Version : How to make certain areas transparent with the desktop?



Sir Rogers
10th March 2010, 10:18
Hey guys,

so I want to make a widget transparent so that the desktop background behind the widget can be seen. How is this possible?

I've tried some paintEvent examples that I found but I didn't get any of them to work properly. If needed the whole widget can be transparent and then I can put a mask on it for the regions that i want to be completely invisible.

The widget is without a windowmanager, so no frame around the form. I'm looking forward to hearing from you.


Regards,
Sir Rogers

manojmka
24th March 2010, 12:08
Were you able to achieve that finally? I am also facing the same issue, I am trying it with Qt::WA_TranslucentBackground

Sir Rogers
26th March 2010, 04:38
Nope unfortunately not. It seems that QT is not supporting this feature at the moment due to lack of cross platform compatibility.

It would be a great feature to have even if it only works on Windows and OS X.


Regards,
Rogers

manojmka
26th March 2010, 05:04
May be you can try setMast(). This works well if you don't want mouse events in masked area but for my case this is not the solution.

laurent
11th May 2010, 02:33
I'm using Qt 4.6.2 on windows and I was able to make a drop shadow for my window using Qt::WA_TranslucentBackground and a ARGB png in the Designer.

In myApp constructor I set the mask with my ARGB background I used in the designer:


QPixmap _pixmap(QString::fromUtf8(":/Background_/Background_/myApp_shadow.png"));
this->setMask(_pixmap.mask());

Here is where I start my QApplication and where I set the flag:

int myApp::Start(int argc, char *argv[])
{
QApplication a(argc, argv);
myApp* w = new myApp(NULL);
w->show();
w->setAttribute(Qt::WA_TranslucentBackground);
return a.exec();
}

Hope I helped you like you helped me ;)

laurent
11th May 2010, 22:08
I forgot to mention that the widget you want to be translucent can't be the top widget, it has to be a child of something here is a working exemple:

m_widgetFrame= new QWidget(0, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
m_widgetFrame->setGeometry(0, 0, 100, 100);
m_widgetFrame->setAttribute(Qt::WA_TranslucentBackground);

m_widgetContent = new QWidget(m_widgetFrame);
m_widgetContent ->setStyleSheet(QString::fromUtf8("QWidget{background-color: qlineargradient(spread:reflect, x1:0, y1:1, x2:0,y2:0,stop:0 rgba(255, 255, 255, 255),stop:1 rgba(255, 255, 255, 0));}"));
m_widgetContent ->setGeometry(0,0,m_widgetFrame->width(),m_widgetFrame->height());

m_widgetFrame->show();