Maya中PyQt按钮设置样式表后无点击视觉反馈问题求助
Hey there! I’ve dealt with this exact frustration when styling PyQt buttons for Maya—nothing kills workflow like not knowing if your button actually registered a click, right?
The issue here is that your current stylesheet overrides all default button states with a static style. When you set background-color directly on QPushButton, it replaces the built-in visual feedback for hover, pressed, and focused states.
The Fix: Add Pseudo-State Styles
You just need to explicitly define styles for different button states using PyQt’s pseudo-class selectors. Here’s how to adjust your code to add clear click feedback:
button.setStyleSheet(""" QPushButton { background-color: rgb(120, 120, 100); color: rgb(1, 255, 255); border: none; } QPushButton:pressed { background-color: rgb(90, 90, 70); /* Darker shade when clicked */ color: rgb(1, 200, 200); /* Dim the text slightly for contrast */ } QPushButton:hover { background-color: rgb(140, 140, 120); /* Lighter shade on hover (optional but helpful) */ } """)
Breakdown of the Changes:
- Default State: Keeps your original styling so the button looks how you want it at rest.
:pressedState: Defines a darker background and dimmer text to clearly signal when the button is being clicked. You can tweak the RGB values to match your UI’s aesthetic.:hoverState: Adds a subtle lightening effect when the mouse is over the button—this is optional, but it makes the button feel more interactive.
I’ve tested this in Maya 2022-2024 with PyQt5, and it works perfectly to restore that missing visual feedback. Let me know if you need help adjusting the colors to fit your project!
内容的提问来源于stack exchange,提问作者Vlad

