Style QToolButton set with QWidgetAction - PySide6
Unsolved
General and Desktop
-
I'm trying to style a QWidgetAction in a QToolBar and following is the minimal reproducible code:
li = [1, 2, 3, 4] class extmenu(QWidget): def __init__(self): super(extmenu, self).__init__() def load(self): lay = QHBoxLayout() for i in li: b = QPushButton() b.setText(str(i)) lay.addWidget(b) self.setLayout(lay) class rtem(QWidget): def __init__(self): super(rtem, self).__init__() self.tb = QToolBar() self.but = QPushButton() self.but.setStyleSheet("background: red;") self.extmen = extmenu() self.extmen.load() self.men = QMenu() self.wid = QWidgetAction(self.but) self.wid.setText("wid") self.wid.setObjectName("wid") self.wid.setDefaultWidget(self.extmen) self.men.addAction(self.wid) self.wid.setMenu(self.men) self.act = QAction("act") self.act.setObjectName("act") self.tb.addAction(self.act) self.tb.addAction(self.wid) self.tb.setStyleSheet("QToolButton#wid{background: red;}") self.lay = QVBoxLayout() self.lay.addWidget(self.tb) self.setLayout(self.lay)
The setStyleSheet does not have any effect on neither "act" or "wid".
self.tb.setStyleSheet("QToolButton{background: red;}") self.tb.setStyleSheet("QToolButton:checked{background: green;}")
The code above works.
Styling self.but obviously does not work.
How do I style the QWidgetAction? And why does stylesheet has no effect on individual QToolButtons?
Thank You.