当前位置:网站首页>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_())

边栏推荐
猜你喜欢

Typora的使用
![[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号](/img/51/e48e222c14f4a4e9f2be91a677033f.png)
[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号

Call the classic architecture and build the model based on the classic
![[go] go implements row column conversion of sets](/img/d9/6272e55b2d9c6b6fbdf2537773bb83.png)
[go] go implements row column conversion of sets

The longest selling mobile phone in China has been selling well since its launch, crushing iphone12

人穷志不短,穷学生也能玩转树莓派

Double position relay dls-5/2 dc220v

【学习笔记】构造
![奇偶链表[链表操作的两种大方向]](/img/4e/ce860bc172bb75f456427ba26a7842.png)
奇偶链表[链表操作的两种大方向]

K210 site helmet
随机推荐
奇偶链表[链表操作的两种大方向]
Flutter Error: Cannot run with sound null safety, because the following dependencies don‘t support
Unhandled Exception: MissingPluginException(No implementation found for method launch on channel)
Typora的使用
Gavin's insight on the transformer live broadcast course - rasa project's actual banking financial BOT Intelligent Business Dialogue robot system startup, language understanding, dialogue decision-mak
Locking relay ydb-100, 100V
为什么要搭建个人博客
关于VCTK数据集
About the general input operation mode of unity
uniapp官方组件点击item无效,解决方案
二十多年来第一次!CVPR最佳学生论文授予中国高校学生!
DC學習筆記正式篇之零——綜述與基本流程介紹
Share your own terminal DIY display banner
Call the classic architecture and build the model based on the classic
None of the following candidates is applicable because of a receiver type mismatch
TypeError: Argument ‘angle‘ can not be treated as a double
Service grid ASM year end summary: how do end users use the service grid?
Principes de formation de la programmation robotique
流批一体在京东的探索与实践
For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!