当前位置:网站首页>qt5-MVC:数据可视化的层次揭秘
qt5-MVC:数据可视化的层次揭秘
2022-07-01 00:41:00 【德天老师】
MVC模式原理
每一个程序都有其原理,我们学习过程中透过他们的原理,来了解他们的工作方向,将会使我们的学习变得无比简单。
揭秘数据层次顺序
- 建立格式布局
- 调用可视化功能
- 建立字符型列表模型
- 定义列表源数据列
- 把数据源列表加入列表模型
- 把列表模型加入可视化功能(可视化点击发射信号–激活消息盒子)
- 消息盒子槽函数,相当于列数数据的功能交互,完成数据消息功能调试
- 将可视化加入布局,相当于摆放到窗口内部
- 激活可视化布局,相当于把数据这块牌匾上面的红布揭开,正式对公众宣传开业。
消息槽函数
def clicked(self,item):
QMessageBox.information()—消息盒子
参数1:继承父类self
参数2:QListView—触发继承自QListView
参数3:盒子信息,信号列表索引item.row()
备注:
item—是列表的内容
.row()—是调用当前内容的显示行索引(0,1,2…)
程序源码
from PyQt5.Qt import *
import sys
app = QApplication([])
class ListView(QWidget):
def __init__(self,parent=None):
super(ListView,self).__init__(parent)
self.setWindowTitle('QListView 例子')
self.resize(300,270)
layout = QVBoxLayout()
listview = QListView()
listmodel = QStringListModel()#字符列表:针对列表显示模型
self.list = ['列表1','列表2','列表3']
listmodel.setStringList(self.list)
listview.setModel(listmodel)
listview.clicked.connect(self.clicked) #发射一个item.row()索引数据给self.clicked
layout.addWidget(listview)
self.setLayout(layout) #布局生效语句,必须写完整,否则添加的可视化模板无法显示
#点击弹出消息盒子,单击每一个列表项会有一个值存储到槽函数item中,item.row()方法会把对应项的索引数据显示出来
def clicked(self,item):
QMessageBox.information(self,'QListView','您选择了'+self.list[item.row()])
win = ListView()
win.show()
sys.exit(app.exec_())

边栏推荐
猜你喜欢

機器人編程的培訓學科類原理

ESP8266 RC522

Install redis database and download redis Desktop Manager in win11

基础知识之二——STA相关的基本定义

Typora的使用

Technical personnel advanced to draw a big picture of business, hand-in-hand teaching is coming

Practical shell knowledge

Day31-t1380-2022-02-15-not answer by yourself

The liquor and tourism sector recovers, and Yaduo continues to dream of listing. How far is it from "the first share of the new accommodation economy"?

Windows环境下安装MongoDB数据库
随机推荐
Poor students can also play raspberry pie
5. TPM module initialization
个人博客搭建与美化
About the general input operation mode of unity
解读创客教育所蕴含的科技素养
Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
Why not two or four TCP handshakes
Koa koa-combine-routers 分路由管理
(learning power + thinking power) x action power, summary of flywheel effect on the growth of technicians
集群与LVS介绍及原理解析
【网络丢包,网络延迟?这款神器帮你搞定所有!】
二十多年来第一次!CVPR最佳学生论文授予中国高校学生!
Q弹松软的大号吐司,带来更舒服的睡眠
Practical shell knowledge
软硬件基础知识学习--小日记(1)
【学习笔记】简单dp
奇偶链表[链表操作的两种大方向]
DC學習筆記正式篇之零——綜述與基本流程介紹
Introduction and principle analysis of cluster and LVS
Solve idea:class' xxx 'not found in module' xxx‘