Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122091

QPushButton with the QMenu won't change pressed style even after menu option was selected and menu was closed

    XMLWordPrintable

Details

    Description

      When I choose an option from the menu, and the menu closes, the button still looks like it is being pressed over and won't change the style to the default state. 

       

      Minimal reproducible example:

      import sys
      
      from PySide6.QtWidgets import (
          QApplication,
          QMainWindow,
          QMenu,
          QPushButton,
          QVBoxLayout,
          QWidget,
      )
      
      
      class ExampleApp(QMainWindow):
          def __init__(self):
              super().__init__()
      
              # Main widget and layout
              centralWidget = QWidget(self)
              self.setCentralWidget(centralWidget)
              layout = QVBoxLayout(centralWidget)
      
              # Create a button
              self.button = QPushButton("Click for options", self)
              # Customize the pressed state for clarity
              self.button.setStyleSheet(
                  "QPushButton:pressed{background-color: #b5b5b5; border: 1px solid black;}"
              )
              layout.addWidget(self.button)
      
              # Create a menu for the button
              self.menu = QMenu(self)
              self.option1 = self.menu.addAction("Option 1")
              self.option2 = self.menu.addAction("Option 2")
      
              # Attach the menu to the button
              self.button.setMenu(self.menu)
      
              # Create a second button for comparison
              self.button_2 = QPushButton("Second button", self)
              layout.addWidget(self.button_2)
      
              # Set main window properties
              self.setWindowTitle("PySide6 Button Menu Example")
              self.setGeometry(300, 300, 300, 200)
      
      
      # Initialize the application
      app = QApplication(sys.argv)
      ex = ExampleApp()
      ex.show()
      
      # Run the application
      sys.exit(app.exec())
       

      The button with the menu doesn't change its pressed style even when hovered or clicked again. And still retains its pressed style even when the second button is clicked, hovered, or focused. When I switch to another window the pressed style also won't change

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              vhilshei Volker Hilsheimer
              monotype Pavlo Popov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes