2 Star 10 Fork 7

终點起點/PySide6-UI-Demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ColumnView.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
终點起點 提交于 2024-06-28 14:21 +08:00 . 新增部分控件
import sys
import os
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
mainlayout = QVBoxLayout()
toolBar =QToolBar()
toolBar.addWidget(QLabel('Current:'))
self.currentEdit = QLineEdit()
toolBar.addWidget(self.currentEdit)
mainlayout.addWidget(toolBar)
self.columnView = QColumnView()
self.columnView.clicked.connect(self.clicked)
mainlayout.addWidget(self.columnView)
self.data = QStandardItemModel()
self.columnView.setModel(self.data)
sichuan=QStandardItem('四川省')
chengdu=QStandardItem('成都市')
chengdu.appendRows([QStandardItem('武侯区'),QStandardItem('青羊区')])
suining=QStandardItem('遂宁市')
suining.appendRows([QStandardItem('船山区'),QStandardItem('安居区')])
sichuan.appendRows([chengdu,suining])
guangdong=QStandardItem('广东省')
guangzhou=QStandardItem('广州市')
guangzhou.appendRows([QStandardItem('天河区'),QStandardItem('越秀区')])
guangdong.appendRows([guangzhou])
self.data.appendRow(sichuan)
self.data.appendRow(guangdong)
self.setLayout(mainlayout)
def clicked(self,index):
#currentIndex=self.columnView.currentIndex()
currentItem=self.data.itemFromIndex(index)
if currentItem is not None:
self.currentEdit.setText(currentItem.text())
self.parent.OnShowMessage(f"current item '{currentItem.text()}'")
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

搜索帮助