当前位置:网站首页>(4) Pyqt designs and implements the [factory production management system] order page - add, delete, modify and query (including source code analysis)
(4) Pyqt designs and implements the [factory production management system] order page - add, delete, modify and query (including source code analysis)
2022-06-12 21:23:00 【six million five hundred and fifty thousand five hundred and tw】
Catalog
One . Effect picture display
1. list
2. Click a row to load data
Two . Sort out the key knowledge points
1. Layout Layouts: Vertical layout , Horizontal layout , Table layout , Form layout .
(1) Set the contents of the header :
(2) Set the content of each cell :
(3) Instantiate the table view
(4) Respond to click events :
(5) Respond to double click events :
(6) Table pagination : The previous page , The next page
4. Log module logging - At the same time, the output log is inverted to the terminal + file
3、 ... and . More cases to explain
One . Effect picture display
1. list

2. Click a row to load data

Two . Sort out the key knowledge points
If you need to understand the basic knowledge points, please move to :
(2) Use Qt Designer Design and implement the first page - land _YYDataV The blog of -CSDN Blog _qtdesigner Sign in
1. Layout Layouts: Vertical layout , Horizontal layout , Table layout , Form layout .
The function of layout is to standardize and tidy page layout , Horizontal layout and vertical layout are commonly used .

Example of horizontal layout :

Example of vertical layout :

2. form TableView:
(1) Set the contents of the header :
# Create a table with specified rows and columns
model = QStandardItemModel(row_len, column_len)
# Set the contents of the header
model.setHorizontalHeaderLabels([' The order number ', ' Order quantity ', ' attribute 1', ' attribute 2', ' attribute 3', ' attribute 4'])
- 1.
- 2.
- 3.
- 4.
- 5.
(2) Set the content of each cell :
# Set the text value of each cell
qst_cnt = QStandardItem(cnt)
model.setItem(row, column, qst_cnt)
- 1.
- 2.
- 3.
(3) Instantiate the table view
# Instantiate the table view , Set the model as a custom model
ui_order.tableView_order_list.setModel(model)
- 1.
- 2.
(4) Respond to click events :
ui_order.tableView_order_list.clicked.connect(tableViewClicked)
- 1.
# Table stand-alone event handling
def tableViewClicked(index:QModelIndex):
# Take the selected line number
row = index.row()
# Take the selected column number
col = index.column()
# Take the contents of the selected table
order_name = ui_order.tableView_order_list.model().index(row, 0).data()
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
(5) Respond to double click events :
ui_order.tableView_order_list.doubleClicked.connect(tableViewDoubleClicked)
- 1.
(6) Table pagination : The previous page , The next page
Every time you read the database 10 Bar record , Reload the table , Start tag for recording current data start and The length of the array len, Used for paging .
3. database Records
# Official documents
# https://pypi.org/project/records/
import time
from log import *
from os import name
import records
from retCode import *
# These lines must be added , otherwise pyinstaller After packing ,exe Run failed
import sqlalchemy.sql.default_comparator
import sqlalchemy.engine.default
from sqlalchemy.dialects import mysql
import pymysql
pymysql.install_as_MySQLdb()
# Connect to database
db = records.Database(
'mysql://root:[email protected]:3306/system')
def keepalive():
try:
db.query('select 1')
time.sleep(10)
except Exception as e:
logger.error(e)
def get_order_by_name(name):
data = []
# Read database
sql = 'select * from t_order where name = "%s"' % (name)
try:
rows = db.query(sql)
data = rows.first(as_dict=True)
except Exception as e:
logger.error(e)
return data
def get_order_list(start = 0, num = 10, sn=""):
data = []
# Read database
sql_condtion = ''
sql = "select * from t_order "
if len(sn) :
sql_condtion = ' where name like "%'+ sn + '%" '
sql_order = " order by time desc limit %d, %d" % (start, num)
sql = sql + sql_condtion + sql_order
try:
rows = db.query(sql)
data = rows.all(as_dict=True)
except Exception as e:
print(e)
return data
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
4. Log module logging - At the same time, the output log is inverted to the terminal + file
import logging
# Output log to file
logger = logging.getLogger(__file__)
# Build a filehandler To record the log in a file
fh = logging.FileHandler("log.txt")
fh.setLevel(logging.DEBUG)
# Build a streamhandler Let's type the log in CMD On the window , The level of error above
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# Format log
formatter = logging.Formatter("%(asctime)s %(threadName)s [line:%(lineno)d] %(levelname)s:%(message)s", datefmt="%Y-%m-%d %H:%M:%S")
ch.setFormatter(formatter)
fh.setFormatter(formatter)
# Corresponding handler Add in logger In the object
logger.addHandler(ch)
logger.addHandler(fh)
# logging.DEBUG Level has no output , Not only do you need to set up logging Of level, You also need to set logger Of level
logger.setLevel(logging.DEBUG)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
3、 ... and . More cases to explain
边栏推荐
- Can flush open an account? Can you directly open the security of securities companies on the app
- Digital intelligence data depth | Bi goes down the altar? It's not that the market has declined, it's that the story has changed
- JS deep and shallow copy
- 二分查找
- Can flush open an account? Can you directly open the security of securities companies on the app? How to open an account online when buying stocks
- Foreign brands become a thing of the past? What are the key words of the TV industry in 2022?
- zgc的垃圾收集的主要阶段
- InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY EB3E94ADBE1229CF
- lintcode:127 · 拓扑排序
- Lua pattern matching
猜你喜欢

Sorting out the knowledge points of primary and secondary indicators

nn. PReLU(planes)

风控建模十:传统建模方法存在的问题探讨及改进方法探索

#141 Linked List Cycle

Access control system based on RFID

leetcode:207. 课程表

Design and practice of Hudi bucket index in byte skipping

String Basics

Lintcode:127. Topology sorting

Data visualization - biaxial comparison effect
随机推荐
结构体知识点all in
Redis cluster mget optimization
Is it safe to open an account in flush? How to open an account online to buy stocks
Fill in the checklist & lt; int> Have default values? [repeat] - fill list & lt; int> with default values? [duplicate]
RestTemplate的@LoadBalance注解
JSON file handles object Tags
China hydraulic cylinder linear position sensor market trend report, technical dynamic innovation and market forecast
Lua pattern matching
Lake shore PT-100 platinum resistance temperature sensor
Pytoch distributed training error
Mxnet record IO details
China hydraulic press market trend report, technical innovation and market forecast
Research Report on hydraulic injection machine industry - market status analysis and development prospect forecast
Data visualization - broken line area chart
一级指针&二级指针知识点梳理
leetcode:210. 课程表 II
Ubuntu 16.04 installing mysql5.6
Principales étapes de la collecte des ordures à Zgc
一款高颜值的MySQL管理工具
插入排序