2012-10-02 159 views
4

我有一個QMenu具有半透明背景和圓邊(邊框半徑)。不幸的是,Windows 7爲這個菜單繪製了一個陰影,這不適合圓角邊緣。它的陰影將爲正常的矩形菜單畫出。Qt QMenu刪除陰影

是否有任何 - 一種完全禁用繪製陰影的QMenu 或 - 一種方法,使陰影適合圓邊 ?

這裏是它發生簡約的例子:

#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(); 
} 

回答

1

這應做到:

w.setWindowFlags(w.windowFlags() | Qt::NoDropShadowWindowHint);