How to put a shadow to a Frameless window in Qt

Thusitha picture Thusitha · Sep 10, 2012 · Viewed 15.7k times · Source

I'm trying to create a Frameless window that has a shadow under it.When we create a borderless window with Qt::FramelessWindowHint flag it doesn't contain a shadow. But we can put shadows to a child widgets easy by creating a QGraphicsDropShadowEffect object and then pass it to the widget through setGraphicsEffect function. But this doesn't seem to work for QMainWindow. Please help me to put shadow to a frameless window in Qt...

Answer

zeFree picture zeFree · Apr 2, 2013

You can do it using this simple hack:


Add a "QWidget" (say widget) to the MainWindow and move everything that's on the MainWindow to the widget. Then do this:

setAttribute(Qt::WA_TranslucentBackground); //enable MainWindow to be transparent

QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
effect->setBlurRadius(5);
ui->widget->setGraphicsEffect(effect);

This seems to work for me. See:

illusion of a main window having a shadow