I need to show shadow around my mainWindow
and I cannot set WA_TranslucentBackground
on it as I need to show a video.
How do I set a shadow for QMainWindow
without making it transparent?
You need to :
Create top level QWidget
Make it translucent and frameless
setWindowFlags(Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground);
Insert your MainWindow into created widget. Left some margins for shadow (about 5-15 px)
Add QGraphicsDropShadowEffect
to MainWindow
:
QGraphicsDropShadowEffect *wndShadow = new QGraphicsDropShadowEffect; wndShadow->setBlurRadius(9.0); wndShadow->setColor(QColor(0, 0, 0, 160)); wndShadow->setOffset(4.0); mainWindow->setGraphicsEffect(wndShadow);
Result: