You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maya中PyQt按钮设置样式表后无点击视觉反馈问题求助

Fixing PyQt Button Click Feedback in Maya

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.
  • :pressed State: 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.
  • :hover State: 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:55:44