qt菜单半透明1234567891011121314151617181920212223242526272829303132QMenu#toptoolbarmenu { padding: 10px 0; border-radius: 15px; background-color: rgba(38, 40, 42, 0.7);}QMenu#toptoolbarmenu::separator { height: 2px; margin: 6px 0; background-color: rgba(255, 255, 255, 1);}QMenu#toptoolbarmenu::icon { padding: 0 0 0 10px;}QMenu#toptoolbarmenu::item { color: white; padding: 3px 10px; font-weight: bold; background-color: transparent;}QMenu#toptoolbarmenu::item:hover,QMenu#toptoolbarmenu::item:pressed,QMenu#toptoolbarmenu::item:selected { color: rgb(95, 174, 200); border-radius: 15px;}QMenu#toptoolbarmenu::item QLabel { color: rgb(145, 145, 145); font-weight: bold; padding-left: 7px; margin-bottom: 5px; background-color: transparent;} main函数里加载qss123456789101112131415// qssQString szStyle;std::string qss = "my.qss";QFile styleFile(qss.string().c_str());if (!styleFile.open(QIODevice::ReadOnly | QIODevice::Text)){ printf("not open qss(%s)!\n", qss.string().c_str());}else{ szStyle = QString(styleFile.readAll()); styleFile.close();}QApplication a(argc, argv);a.setStyleSheet(szStyle); 对话框内构造menu 123456QMenu menu_(this);menu_.setObjectName("toptoolbarmenu");// Qt::NoDropShadowWindowHint 去掉阴影// Qt::FramelessWindowHint 无边框menu_.setWindowFlags(impl->menu_.windowFlags() | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);menu_.setAttribute(Qt::WA_TranslucentBackground);