PYQT5(5)带跳转按钮的QTableWidgets
2018-12-29 本文已影响0人
弗兰克万岁
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem
class btn_table(QTableWidget):
def __init__(self,x,y,window,res):
self.centralwidget = QtWidgets.QWidget(window)
self.centralwidget.setObjectName("centralwidget")
self.centralwidget.resize(500,500)
super().__init__(self.centralwidget)
self.setGeometry(QtCore.QRect(20, 10, 471, 401))
self.setObjectName("client_table")
self.setColumnCount(x)
self.setRowCount(y)
self.buttonForRow(res)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
def buttonForRow(self,res):#添加内容并在最后一行添加一个按钮
# requir:[[value1,value2,value3,...],[value1,value2,value3,value4,...]]
self.clear()
for i in range(0,len(res)):
try:
item = self.horizontalHeaderItem(i)
self.setHorizontalHeaderItem(i, item)
except Exception as e:
print(e)
t = QtWidgets.QTableWidgetItem()
self.setHorizontalHeaderItem(i, t)
item = self.horizontalHeaderItem(i)
for a in range(0,len(res[i])):
self.setItem(i,a,QtWidgets.QTableWidgetItem(str(res[i][a])))
print(res[i][a])
# self.setItem(i, 1, QtWidgets.QTableWidgetItem(str(res[i][1])))
btn=self.GenerateBtn(res[i][1])
self.setCellWidget(i,len(res[0]),btn)
def GenerateBtn(self,clientid):
viewBtn = QtWidgets.QPushButton('查看')
viewBtn.setStyleSheet(''' text-align : center;
background-color : DarkSeaGreen;
height : 30px;
border-style: outset;
color:white;
font : 13px; ''')
viewBtn.clicked.connect(lambda:self.jump(clientid) )
return viewBtn
def jump(self,clientid):
print(clientid)