pel*_*los 2 pyqt colors button stylesheet
我正在尝试在按下时更改按钮的颜色,看起来可以直接在样式表中完成,然后执行功能然后连接它.
在 http://qt.developpez.com/doc/4.7-snapshot/stylesheet-examples/中 显示此示例:
QPushButton#evilButton {
background-color: red;
border-style: outset;
border-width: 2px;
border-radius: 10px;
border-color: beige;
font: bold 14px;
min-width: 10em;
padding: 6px;
}
QPushButton#evilButton:pressed {
background-color: rgb(224, 0, 0);
border-style: inset;
}
Run Code Online (Sandbox Code Playgroud)
怎么能把它翻译成python pyqt?
我能够让它像这样工作,这样颜色按钮是蓝色的,按下时更改为红色
btn_text = QString("this font color")
btn = QPushButton(btn_text)
btn.setStyleSheet("QPushButton { background-color: blue }"
"QPushButton:pressed { background-color: red }" )
Run Code Online (Sandbox Code Playgroud)
不需要翻译,它是一个样式表:qt 使用的文本文档(因此 pyqt 使用,因为 pyqt 调用 qt)。例如:
self.groupBox.setStyleSheet("""
QGroupBox
{
background-color: rgb(255, 255,255);
border:1px solid rgb(255, 170, 255);
}
"""
)
Run Code Online (Sandbox Code Playgroud)