非常抱歉,我之前的回答中存在错误。在PySide6中,设置按钮的颜色可以使用`setStyleSheet`方法。以下是修正后的代码:from PySide6.QtWidgets import QApplication, QMainWindow, QPushButtonclass MainWindow(QMainWindow): def __init__(self): super().__init__() self.button = QPushButton("开始计算", self) self.button.clicked.connect(self.start_calculation) self.setCentralWidget(self.button) def start_calculation(self): self.button.setEnabled(False) self.button.setStyleSheet("background-color: gray") # 执行长时间计算的代码 # 计算完成后恢复按钮状态 self.button.setEnabled(True) self.button.setStyleSheet("")if __name__ == '__main__': app = QApplication() window = MainWindow() window.show() app.exec()在上述代码中,通过使用`setStyleSheet`方法将按钮的背景颜色设置为灰色。当按钮被禁用时,它会显示为灰色背景。在计算完成后,我们将按钮恢复为可用状态,并使用空字符串将样式表重置为默认值,使按钮恢复正常外观。希望这次的回答能够解决你的问题,如果还有其他疑问,请随时提问。再次对给你带来困扰表示抱歉。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。