当前位置:网站首页>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_())
边栏推荐
- Poor students can also play raspberry pie
- Kongyiji's first question: how much do you know about service communication?
- Introduction and principle analysis of cluster and LVS
- 软件开发完整流程
- Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base
- DC學習筆記正式篇之零——綜述與基本流程介紹
- StrictMode分析Registion-StrictMode原理(4)
- 分割链表[先取next再斩断链表防止断链]
- StrictMode带来的思考-StrictMode原理(5)
- pytorch编程知识(2)
猜你喜欢
随机推荐
Docker deployment MySQL 8
(learning power + thinking power) x action power, summary of flywheel effect on the growth of technicians
ESP8266 RC522
uniapp官方组件点击item无效,解决方案
2021电赛F题openmv和K210调用openmv api巡线,完全开源。
Flutter Error: Cannot run with sound null safety, because the following dependencies don‘t support
Service grid ASM year end summary: how do end users use the service grid?
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"?
DLS-42/6-4 DC110V双位置继电器
使用StrictMode-StrictMode原理(1)
二十多年来第一次!CVPR最佳学生论文授予中国高校学生!
闭锁继电器YDB-100、100V
pull_ to_ refresh
Listview in flutter application development
New content violation degree determination scana bad information monitoring capability update issue 5
Fluent JSON serialization deserialization
5. TPM module initialization
做生意更加务实
None of the following candidates is applicable because of a receiver type mismatch
Chromatic judgement bipartite graph