#include "customMenu.h" #include CustomMenu::CustomMenu(QWidget* parent) :QMenu(parent) { setWindowFlags(windowFlags() | Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground); //设置阴影 QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(this); shadow->setBlurRadius(12); //模糊半径 shadow->setOffset(4, 4); //偏移量 shadow->setColor(QColor(0, 0, 0, 200)); //阴影颜色 setGraphicsEffect(shadow); //qss setStyleSheet("QMenu{\n" " margin:16px;\n" " padding:2px;\n" " color:rgb(240, 240, 240);\n" " background-color:rgb(45, 45, 45);\n" " border:1px solid rgb(0, 0, 0);\n" "}\n" "QMenu:item{\n" " height:21px;\n" "}\n" "QMenu:item:text{\n" " padding-left:15px;\n" " padding-right:15px;\n" "}\n" "QMenu:item:disabled{\n" " color:rgb(140, 140, 140);\n" "}\n" "QMenu::separator{\n" " height:1px;\n" " background:rgb(10, 10, 10);\n" " margin-left:1px;\n" " margin-right:1px;\n" "}\n" "QMenu:item:selected{\n" " background-color: rgba(49, 91, 125, 180);\n" "}\n"); } CustomMenu::~CustomMenu() { }