Python QT如何可视化按钮被点击

Python QT how to visualise that the button is clicked

我有一个 QtCreator 生成的图形用户界面。导入后,我将图像设置为按钮,当我单击它们时,下面的按钮可能表示单击,但 QIcon 没有任何变化。有没有办法让它可见? 这是我的按钮代码:

 self.pushButton.setIcon(QtGui.QIcon('artwork/player_rew'))
 self.pushButton.setIconSize(QtCore.QSize(48, 48))
 self.pushButton.setStyleSheet('QPushButton{border: 0px solid;}')

您可以在样式 sheet 中使用 :pressed pseudo-state 来指定按下按钮时的行为:

self.pushButton.setStyleSheet("""
    QPushButton{
        border: 0px solid;
    }
    QPushButton:pressed {
        border: 0px solid;
        image: url(some_different_image);
        background-color: red;
    }
""")

更多信息也可以在 Qt Style Sheets Examples

中找到