-
Notifications
You must be signed in to change notification settings - Fork 0
/
datalistview.py
88 lines (72 loc) · 2.57 KB
/
datalistview.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#coding: utf-8
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5 import uic
import os
import sys
import config
uifile = os.path.join(config.APP_DIR, 'datalistview.ui')
ui_mainwindow, qtbaseclass = uic.loadUiType(uifile)
class DataListView(ui_mainwindow, qtbaseclass):
# 数据模型
model = None
# header=('1','2','3','4')
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
# 调整界面大小
self.setGeometry(0, 0, config.APP_SIZE_WIDTH, config.APP_SIZE_HEIGHT)
# 设置左右图标
left_ico = os.path.join(config.APP_DIR, config.APP_ICO_LEFT)
right_ico = os.path.join(config.APP_DIR, config.APP_ICO_RIGHT)
self.setLogoLeft(left_ico)
self.setLogoRight(right_ico)
def setTableAutoStretch(self):
# 设置表格自动填充
# self.tableView.horizontalHeader().setStretchLastSection(True)
self.tableView.horizontalHeader().setSectionResizeMode(
QHeaderView.Stretch)
# self.tableView.verticalHeader().setDefaultSectionSize(50)
# self.tableView.verticalHeader().hide()
def setTableTitle(self, title):
self.tableTitle.setText(title)
def setTableReadOnly(self):
'''设置数据表只读'''
# 设置表格只读
self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
def setModel(self, model):
self.model = model
self.tableView.setModel(model)
def slot_table_click(self, index):
'''表格点击事件处理
- index 点击索引
'''
pass
def setLogoLeft(self, imgPath):
img = QtGui.QImage(imgPath)
icon = img.scaled(50, 50)
pix = QtGui.QPixmap()
self.logo_left.setPixmap(pix.fromImage(icon))
def setLogoRight(self, imgPath):
img = QtGui.QImage(imgPath)
icon = img.scaled(50, 50)
pix = QtGui.QPixmap()
self.logo_right.setPixmap(pix.fromImage(icon))
def slot_close_click(self):
'''关闭按钮点击事件'''
self.reject()
def keyPressEvent(self, event):
'''重写键盘响应事件'''
if event.key() == QtCore.Qt.Key_Escape:
# 不处理ESC按键
pass
else:
super().keyPressEvent(event)
if __name__ == '__main__':
# d = DBManager()
# d.create()
app = QApplication(sys.argv)
w = DataListView()
w.setTableTitle('数据显示')
w.show()
sys.exit(app.exec_())