当前位置:网站首页>QT5-布局在创作中的理解应用
QT5-布局在创作中的理解应用
2022-07-01 00:41:00 【德天老师】
程序设计的核心
为了熟练学习和理解程序的重要作用,需要不断的进行不同类型的作品设计,从而体会程序编写的技巧和方法。
from PyQt5.Qt import *
import sys
app = QApplication([])
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('DT系统')
self.resize(1248,450)
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
#在垂直布局 添加水平布局,第一层
layout = QVBoxLayout()
top_lout = QHBoxLayout() #顶层水平布局
btn_start = QPushButton()
btn_start.setText('开始')
top_lout.addWidget(btn_start) #按钮添加到布局之中
btn_stop = QPushButton()
btn_stop.setText('停止')
top_lout.addWidget(btn_stop)
top_lout.addStretch() #右侧添加弹簧使两按钮左方靠近
layout.addLayout(top_lout) #顶层布局添加到总布局
layout.addStretch() #对总布局添加一个弹簧,使前2个水平布局靠向上方。
mid_lout = QHBoxLayout() #中间水平布局
le = QLineEdit()
mid_lout.addWidget(le) #添加文字输入框到中间水平布局
btn_stop = QPushButton()
btn_stop.setText('添加')
mid_lout.addWidget(btn_stop) #添加按钮到中间水平布局
layout.addLayout(mid_lout) #中间水平布局添加到总布局
#创建表格布局
table_layout = QHBoxLayout()
tw = QTableWidget(0, 8) #添加2行,共计8列
table_header = [
{"field":"asin","text":"ASIN",'width':120},
{"field":"title","text":"标题",'width':150},
{"field":"url","text":"URL",'width':400},
{"field":"price","text":"底价",'width':100},
{"field":"success","text":"成功次数",'width':100},
{"field":"error","text":"503次数",'width':100},
{"field":"status","text":"状态",'width':100},
{"field":"frequency","text":"频率(N秒/次)",'width':100}]
for idx,info in enumerate(table_header):
item = QTableWidgetItem()
item.setText(info['text']) #通过循环获取字典key='Text'的值
tw.setHorizontalHeaderItem(idx, item) #idx从0-7,匹配1~8列,item是对应的text的值作为列名
tw.setColumnWidth(idx, 112)
item = QTableWidgetItem()
item.setText('网址')
tw.setHorizontalHeaderItem(1, item)
tw.setColumnWidth(1, 400)
table_layout.addWidget(tw)
layout.addLayout(table_layout)
layout.addStretch() #添加弹簧到总布局中
bottom_lout = QHBoxLayout() #底部的一个水平区
bottom_lout.addStretch() #左侧添加的挤压命令
lab = QLabel('创作:德天老师') #在上面挤压命令下靠右侧对齐
bottom_lout.addWidget(lab) #标签添加到底部的水平区域
layout.addLayout(bottom_lout)
self.setLayout(layout) #布局与窗口绑定,通过窗口显示
win = Window()
win.show()
sys.exit(app.exec_())

边栏推荐
- Double position relay dls-5/2 dc220v
- mustache语法
- 基础知识之三——标准单元库
- [go] go implements row column conversion of sets
- Service grid ASM year end summary: how do end users use the service grid?
- New content violation degree determination scana bad information monitoring capability update issue 5
- K210工地安全帽
- Inspire students' diversified thinking with steam Education
- pull_ to_ refresh
- [learning notes] simple DP
猜你喜欢

Analyze the maker education path integrating the essence of discipline

Service
![Parity linked list [two general directions of linked list operation]](/img/4e/ce860bc172bb75f456427ba26a7842.png)
Parity linked list [two general directions of linked list operation]

Interpreting the scientific and technological literacy contained in maker Education

Impact relay zc-23/dc220v

蒹葭苍苍,白露为霜。

基础知识之一——STA基础概述

Kongyiji's first question: how much do you know about service communication?

技术人进阶画业务大图,手把手教学来了

数字IC设计流程总结
随机推荐
Dx-11q signal relay
Installing mongodb database in Windows Environment
基础知识之二——STA相关的基本定义
解读创客教育所蕴含的科技素养
Analyzing the wisdom principle in maker education practice
Share your own terminal DIY display banner
Pre training / transfer learning of models
None of the following candidates is applicable because of a receiver type mismatch
Docker 部署 MySQL 8
软硬件基础知识学习--小日记(1)
OCR的一些项目
C# 自定义并动态切换光标
How to scroll uitableview to a specific position - how to scroll uitableview to specific position
Exploring the road of steam education innovation in the Internet Era
Mustache syntax
pull_ to_ refresh
Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
自定义注解实现校验
关于Unity一般的输入操作方式
DX-11Q信号继电器