gpt4 book ai didi

button - pyqt 使用样式表按下按钮时更改按钮的颜色

转载 作者:行者123 更新时间:2023-12-02 02:57:01 27 4
gpt4 key购买 nike

我正在尝试在按下按钮时更改按钮的颜色,看起来可以直接在样式表中完成,而无需执行功能然后连接它。

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;
}

如何将其转换为 python pyqt?

最佳答案

我能够让它像这样工作,这样颜色按钮是蓝色的,按下时会变成红色

    btn_text = QString("this font color")
btn = QPushButton(btn_text)

btn.setStyleSheet("QPushButton { background-color: blue }"
"QPushButton:pressed { background-color: red }" )

关于button - pyqt 使用样式表按下按钮时更改按钮的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21294267/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com