代码拉取完成,页面将自动刷新
import sys
import os
from PySide6.QtGui import QPaintEvent
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *
class Demo(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
layout = QVBoxLayout()
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
toolBar=QToolBar()
toolBar.addWidget(QLabel("Color:"))
cb=QComboBox()
cb.addItems(Qt.GlobalColor.__members__.keys())
cb.currentTextChanged.connect(self.OnColorChanged)
toolBar.addWidget(cb)
toolBar.addWidget(QLabel("Style:"))
cb=QComboBox()
cb.addItems(Qt.BrushStyle.__members__.keys())
cb.currentTextChanged.connect(self.OnStyleChanged)
toolBar.addWidget(cb)
layout.addWidget(toolBar)
self.brush=QBrush()
self.setLayout(layout)
def paintEvent(self, event: QPaintEvent):
rect=QRect(50,50,150,150)
painter=QPainter(self)
painter.setBrush(self.brush)
painter.drawRoundedRect(rect,10,10,Qt.SizeMode.RelativeSize)
def OnColorChanged(self,text):
color=Qt.GlobalColor[text]
self.brush.setColor(color)
self.update()
self.parent.OnShowMessage(f"Set Color:{color}")
def OnStyleChanged(self,text):
style=Qt.BrushStyle[text]
self.brush.setStyle(style)
self.update()
self.parent.OnShowMessage(f"Set Style:{style}")
def runDemo(parent):
wigdet = Demo(parent)
return wigdet
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。