haris
haris

Reputation: 152

How to set the shadow around the window

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?

Upvotes: 1

Views: 4350

Answers (1)

t3ft3l--i
t3ft3l--i

Reputation: 1412

You need to :

  1. Create top level QWidget

  2. Make it translucent and frameless

    setWindowFlags(Qt::FramelessWindowHint);    
    setAttribute(Qt::WA_TranslucentBackground);
    
  3. Insert your MainWindow into created widget. Left some margins for shadow (about 5-15 px)

  4. 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:

A widget with drop shadow

Upvotes: 4

Related Questions