2 Star 10 Fork 7

终點起點/PySide6-UI-Demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
BrushStyle.py 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
终點起點 提交于 2024-08-23 16:48 +08:00 . 增加其他demo
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/johnjiangw/pyside6-ui-demo.git
git@gitee.com:johnjiangw/pyside6-ui-demo.git
johnjiangw
pyside6-ui-demo
PySide6-UI-Demo
master

搜索帮助