You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置PyQt画笔样式的背景颜色?

修改CrossPattern交叉图案为蓝色

你只需要将QColor('orange')替换为QColor('blue')即可,修改后的完整代码如下:

brush = QtGui.QBrush()
brush.setColor(QtGui.QColor('blue'))  # 替换原有的orange为blue
brush.setStyle(QtCore.Qt.CrossPattern)

scene = QtWidgets.QGraphicsScene()
view = QtWidgets.QGraphicsView(scene)

it = scene.addRect(QtCore.QRectF(0, 0, 400, 400))
it.setBrush(brush)

view.resize(640, 480)
view.show()

如果需要特定色调的蓝色,也可以通过RGB值自定义,比如深蓝色:

brush.setColor(QtGui.QColor(0, 0, 255))  # 纯蓝色RGB值
# 或者使用预定义的深色蓝名称
brush.setColor(QtGui.QColor('darkblue'))

内容的提问来源于stack exchange,提问作者Laeti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 10:20:02