I need to style QMenu from external style.css, actually I have style.css already included in my project but can’t find solution to style this drop down menu directly from CSS file, this is important part of script
import subprocess
from core.widgets.base import BaseWidget
from core.validation.widgets.yasb.power_button import VALIDATION_SCHEMA
from PyQt6.QtWidgets import QPushButton, QMenu, QApplication
from PyQt6 import QtCore, QtGui
from core.config import get_stylesheet_path
class PowerButton(QPushButton):
def __init__(self, button_label: str):
super().__init__()
self.setText(button_label)
self.setProperty("class", "power-button")
self.setIcon(QtGui.QIcon(QtGui.QPixmap(1, 1)))
self.setStyleSheet("""
QPushButton {
border: none;
}
QPushButton::menu-indicator {
image: none;
width: 0px;
color:transparent;
height: 0px;
}
""")
class PowerMenu(QMenu):
def __init__(self, itemAmount=3, itemHeight=16):
super().__init__()
self.setMinimumSize(150, itemHeight * itemAmount)
self.radius = 8
self.setProperty("class", "power-button-menu")
self.setStyleSheet('''
QMenu {{
background: rgb(10, 10, 10);
border-radius: 4px;
margin-top: 8px;
margin-right: 8px;
text-align: center;
padding: 8px;
}}
QMenu::item {{
color: white;
font-size: 14px;
padding: 8px;
margin-right:6px;
margin-top:6px;
font-family: 'Segoe UI';
}}
QMenu::item:selected {{
border-radius: 4px;
background: rgb(20, 30, 40);
}}
'''.format(radius=self.radius))
For example I can access .power-button via css file but there is any way to access QMenu::item
and QMenu::item:selected
so I can remove it from .py and play with style in my style.css