Ai
1 Star 0 Fork 10

小麦/PySide6-UI-Demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ToolBox.py 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
终點起點 提交于 2024-06-28 14:21 +08:00 . 新增部分控件
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()
toolBar = QToolBar()
btn = QPushButton('Add')
btn.clicked.connect(self.OnAddClicked)
toolBar.addWidget(btn)
btn = QPushButton('Insert')
btn.clicked.connect(self.OnInsertClicked)
toolBar.addWidget(btn)
'''btn = QPushButton('Delete')
btn.clicked.connect(self.OnDeleteClicked)
toolLayout.addWidget(btn)'''
layout.addWidget(toolBar)
self.toolbox = QToolBox()
self.toolbox.currentChanged.connect(self.OnCurrentChanged)
buttonWidget = QWidget()
self.buttonLayout = QVBoxLayout()
self.buttonLayout.setAlignment(Qt.AlignmentFlag.AlignTop)
self.buttonLayout.addWidget(QPushButton('PushButton',objectName='PushButton'))
self.buttonLayout.addWidget(QRadioButton('RadioButton',objectName='RadioButton'))
toolbtn=QToolButton(objectName='ToolButton')
toolbtn.setIcon(QIcon(f'{self.parent.getAppDir()}/resources/confirm.png'))
self.buttonLayout.addWidget(toolbtn)
self.buttonLayout.addWidget(QCommandLinkButton('CommandLikButton',objectName='CommandLikButton'))
buttonWidget.setLayout(self.buttonLayout)
self.toolbox.addItem(buttonWidget,'Buttons')
#self.toolbox.addItem(QPushButton('PushButton'),'Buttons')
#self.toolbox.addItem(QRadioButton('RadioButton'),'Buttons')
#self.toolbox.addItem(QToolButton(),'Buttons')
#self.toolbox.addItem(QCommandLinkButton('CommandLikButton'),'Buttons')
self.toolbox.addItem(QListView(),'Views')
layout.addWidget(self.toolbox)
self.setLayout(layout)
def OnAddClicked(self):
widgetName = f'Checkbox{random.randint(1,100)}'
self.buttonLayout.addWidget(QCheckBox(widgetName,objectName=widgetName))
self.parent.OnShowMessage(f"Add Checkbox:{widgetName}")
def OnInsertClicked(self):
index = self.toolbox.currentIndex()
if index ==-1:
index=0
widgetName = f'Checkbox{random.randint(1,100)}'
self.buttonLayout.insertWidget(index,QCheckBox(widgetName,objectName=widgetName))
self.parent.OnShowMessage(f"Insert {widgetName} at {index}")
'''def OnDeleteClicked(self):
current = self.toolbox.currentWidget()
if current is None:return
self.parent.OnShowMessage(f"Delete item,Name={current.objectName()}")
self.buttonLayout.removeWidget(current)'''
def OnCurrentChanged(self,index):
self.parent.OnShowMessage(f"Current index={index}")
def runDemo(parent):
wigdet = Demo(parent)
return wigdet
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hmz-xm/pyside6-ui-demo.git
git@gitee.com:hmz-xm/pyside6-ui-demo.git
hmz-xm
pyside6-ui-demo
PySide6-UI-Demo
master

搜索帮助