I'm creating an app in PyQt5 in Python and i'm trying to customize the way the QMenu() looks. With setting some Window Flags and styling, I was able to make the menu look like this:
And this is my code:
def main():
app = QApplication(sys.argv)
win = QMainWindow()
app.setStyleSheet('''
QMenu {
background: #2b2b2b;
color: white;
border-radius: 5px;
border: 1px solid #3e3e3e;
}
QMenu::item {
border-radius: 3px;
padding: 4px 25px;
margin: 2px 5px;
}
QMenu::item:selected {
background: #353535;
}
''')
menubar = QMenuBar()
settingsmenu = QMenu(menubar)
settingsmenu.setTitle("Settings")
settingsmenu.setWindowFlags(settingsmenu.windowFlags() | QtCore.Qt.FramelessWindowHint)
settingsmenu.setWindowFlags(settingsmenu.windowFlags() | QtCore.Qt.NoDropShadowWindowHint)
settingsmenu.setAttribute(QtCore.Qt.WA_TranslucentBackground)
run_on_start = QAction(text="Run On Startup", checkable=True)
start_minimized = QAction(text="Start Minimized", checkable=True)
settingsmenu.addAction(run_on_start)
settingsmenu.addAction(start_minimized)
menubar.addAction(settingsmenu.menuAction())
win.setMenuBar(menubar)
win.show()
sys.exit(app.exec_())
main()
I got rid of the default PyQt5 box-shadow, because I think it's ugly and too harsh.
This is exactly how I want it to look, except I want it to have some sort of a shadow around it (just not the default one). Menu's from other applications all seem to have exactly the same shadow, which means that Windows itself probably applies these shadows to them as seen below:
The menu from VS Code with a subtle drop-shadow
The (tray)menu from Spotify with that same drop-shadow (A little harder to see)
And this is my menu with the default shadow (the app is called 'Playtimer')
So my question is: Is there a way to let Windows know that the menu needs a shadow, just not the default one.
Let me know if you need to know anything else to answer my question.



