Ai
1 Star 0 Fork 10

marlin/PySide6-UI-Demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ColorDialog.py 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
终點起點 提交于 2024-08-23 16:48 +08:00 . 增加其他demo
import sys
import os
import random
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('CustomColor:'))
self.custom=QLineEdit()
#self.custom.setText('#ffff00')
toolBar.addWidget(self.custom)
toolBar.addWidget(QLabel("Options:"))
self.optonCombox=QComboBox()
self.optonCombox.addItems(QColorDialog.ColorDialogOption.__members__.keys())
toolBar.addWidget(self.optonCombox)
btn=QPushButton('ShowColorDialog')
btn.clicked.connect(self.OnShowDialog)
toolBar.addWidget(btn)
layout.addWidget(toolBar)
self.label=QLabel('Hello 测试颜色选择')
layout.addWidget(self.label)
self.setLayout(layout)
def OnShowDialog(self):
dialog=QColorDialog()#全局的,每次加的自定义颜色都被保留了
if len(self.custom.text())>0:
index=random.randint(0,dialog.customCount())
dialog.setCustomColor(index,self.custom.text())
self.parent.OnShowMessage(f'Set CustomColor {self.custom.text()} at {index}')
option=QColorDialog.ColorDialogOption[self.optonCombox.currentText()]
color= dialog.getColor(self.label.palette().color(QPalette.ColorRole.WindowText),self,'Select Color',option)
if color.isValid():
palette=self.label.palette()
palette.setColor(QPalette.ColorRole.WindowText,color)
self.label.setPalette(palette)
self.parent.OnShowMessage(f'Selected Color:{color.name()}')
def runDemo(parent):
wigdet = Demo(parent)
return wigdet
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/maxf110415/pyside6-ui-demo.git
git@gitee.com:maxf110415/pyside6-ui-demo.git
maxf110415
pyside6-ui-demo
PySide6-UI-Demo
master

搜索帮助