Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Style QToolButton set with QWidgetAction - PySide6

Style QToolButton set with QWidgetAction - PySide6

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 205 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tIk90wT
    wrote on last edited by tIk90wT
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved