Qt QMenu removes the shadow

I have a QMenu with a translucent background and rounded edges (border-radius). Unfortunately, Windows 7 draws a shadow for this menu, which does not fit the rounded edges. Its shadow to be drawn for regular rectangular menus.

Is there a way to completely disable shadow drawing for QMenu, or is there a way to make the shadow fit to rounded edges

Here is a minimalist example where it occurs:

#include <QApplication> #include <QPushButton> #include <QMenu> int main(int argc, char *argv[]) { QApplication a(argc, argv); QPushButton b("press me"); QMenu m; m.addAction("hello"); m.addAction("world"); m.setWindowFlags(m.windowFlags() | Qt::FramelessWindowHint); m.setAttribute(Qt::WA_TranslucentBackground); m.setStyleSheet("background:rgba(255,0,0,50%); border-radius:5px;"); b.setMenu(&m); b.show(); return a.exec(); } 
+4
source share
1 answer

This should do it:

 w.setWindowFlags(w.windowFlags() | Qt::NoDropShadowWindowHint); 
+1
source

Source: https://habr.com/ru/post/1437389/


All Articles