Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt QMenu remove drop shadow

Tags:

qt

qmenu

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

Is there either - a way to completely disable drawing drop shadows for QMenu or - a way to make the shadow fit to the rounded edges ?

Here is a minimalistic 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();
}
like image 740
user1703711 Avatar asked Oct 02 '12 13:10

user1703711


1 Answers

This should do it:

w.setWindowFlags(w.windowFlags() | Qt::NoDropShadowWindowHint);
like image 160
Sergio Martins Avatar answered Sep 23 '22 19:09

Sergio Martins