python - 背景中的多种颜色(过渡)

标签 python python-3.x pyqt qtstylesheets

有没有办法在 PyQt 中将过渡颜色作为背景? 我尝试使用 CSS 的线性渐变,但不起作用

stylesheet = ("QWidget { background-color : linear-gradient(to right, red 50%, blue 50%);}")

如何让它为我工作?

最佳答案

我使用 x1, x2 而不是 to right 手动指定渐变的开始和停止坐标,并添加了 stop 关键字。

stylesheet = "QWidget {background-color: qlineargradient(x1: 0, x2: 1, stop: 0 red, stop: 1 blue)}"

enter image description here

或者您想要这样的急剧转变吗?

stylesheet = "QWidget {background-color: qlineargradient(x1:0, x2:1, stop: 0.49 red, stop: 0.51 blue)}"

enter image description here

关于python - 背景中的多种颜色(过渡),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64835508/

相关文章:

python - 如何使用 Python 查找系统类型?

python-3.x - 我如何接受字典/对象作为 Graphite 烯(GraphQL)突变的输入?

python - 当我在主窗口中调用其他 QtWidget 时,我的 GUI 不起作用(按钮等)

c++ - Qt如何检查按下了哪个鼠标按钮

python - 在 PyQt 中启动 new QThread() 时传递参数

python - 如何在Python中以编程方式调用函数并以编程方式指定模块?

python - 如何解释此错误 "UnicodeDecodeError: ' ascii' 编解码器无法解码位置 164 : ordinal not in range(128)"中的字节 0xe2

python - 类型错误 : Object of type bool_ is not JSON serializable

python - 主循环不等待 python 多处理池完成并卡住

python - 如何使用 django-rest 框架测试客户端发布列表