QMdiSubWindow with transparency and opacity
-
Hi guys,
I trying to create new QMdiSubWindow with transparency and opacity to be able to see the background of QMdiArea.
I try to overwrite paintEvent like this:
void MdiSubWindow::paintEvent(QPaintEvent *aEvent) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setOpacity(0.5); painter.setBrush(Qt::red); painter.drawRoundedRect(0, 0 , width(), height(), 20.0, 20.0); // QWidget::paintEvent(aEvent); }
And then a in CSS try this:
QMdiSubWindow { border: 1px solid transparent; border-radius: 100px; opacity: 0.5; background: tranparent; } QMdiSubWindow QWidget { background: transparent; } QMdiSubWindow:title { height: 18px; background: transparent; } QMdiSubWindow #accept { background: green; border: 1px solid #000000; margin: 10px; border-radius: 5px; } QMdiSubWindow #cancel { background: red; border: 1px solid #000000; margin: 10px; border-radius: 5px; }
The window look like this:
But i cant remove the default background of QMdiSubWindow. Can anyone help me?
-
@scastiello You cas use
setAttribute(Qt::WA_NoBackground);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_DeleteOnClose);in your MdiSubWindow class
-
It works perfectly , thank you very much. :)
-
@scastiello ;)
-
Hi,
@Malek_Khlif said:
setAttribute(Qt::WA_DeleteOnClose);
Just beware, that one has nothing to do with painting. Depending on how you handle your mdi sub windows you will have surprises.
-
Yes of course