1 Attachment(s)
QGraphicsView and adding QWidget with transparent areas
Hello,
I want to use my own Button-Widget in a QGraphicsView. Adding and displaying the widget works fine. Unfortunately this Button has round corners which are not displayed transparent in the view tree. When I use the the same widget in a QMainWindow the outside areas are drawn transparent. The same effect occur by using a default Qt-Widget like QDial.
This code shows the widget with transparent behavior:
(I used QTextEdit just to get (quick and dirty) a white background)
Code:
int main(int argc, char *argv[])
{
pEdit->setGeometry(0,0,main.size().width(),main.size().height());
pDial->setGeometry(40,00,100,100);
main.show();
return a.exec();
}
The following code shows the same widget in a QGraphicsView with opaque behavior:
Code:
int main(int argc, char *argv[])
{
scene.setBackgroundBrush(Qt::white);
QGraphicsProxyWidget * pWidget = scene.addWidget(pDial,Qt::Widget);
view.show();
return a.exec();
}
Can anyone give me a hint how to render the widget with transparent corners?
Thanks in advance!
Denis
Re: QGraphicsView and adding QWidget with transparent areas
Why did u set background of scene as white ?
You should try setting background of scene and view as transparent. And also you can set the top level window flag WA_TranslucentBackground (chk spelling :D) .
There was also some example on Qt Labs where graphics item with transparent background were used... cant remember the link :(
Re: QGraphicsView and adding QWidget with transparent areas
hi aamer4yu,
the hint with the WA_TranslucentBackground flag was all I needed. Setting this flag in the constructor of the derrived widget sets the background to transparent.
Thank you very much!