Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
6.6.1
-
None
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
- duplicates
-
QTBUG-120976 REG: QPushButton of a menu will still appear pressed even after you click somewhere outside the button area.
- Closed