for i in xrange(self.datacount):
self.btn[i] = QPushButton("Edit")
for i in xrange(self.datacount):
self.data0 = str(self.data[i][0])
self.data1 = str(self.data[i][1])
self.data2 = str(self.data[i][2])
self.data3 = str(self.data[i][3])
self.data4 = str(self.data[i][4])
self.data5 = str(self.data[i][5])
self.window.tableWidget.setItem(i, 0, QtGui.QTableWidgetItem(self.data0))
self.window.tableWidget.setItem(i, 1, QtGui.QTableWidgetItem(self.data1))
self.window.tableWidget.setItem(i, 2, QtGui.QTableWidgetItem(self.data2))
self.window.tableWidget.setItem(i, 3, QtGui.QTableWidgetItem(self.data3))
self.window.tableWidget.setItem(i, 4, QtGui.QTableWidgetItem(self.data4))
self.window.tableWidget.setItem(i, 5, QtGui.QTableWidgetItem(self.data5))
self.window.tableWidget.setCellWidget(i, 6, self.btn[i]);
QtCore.QObject.connect(self.btn[i], QtCore.SIGNAL("clicked()"), lambda: self.StartStop(i))
# coding=utf-8
import sys
from PyQt4 import QtGui
from PyQt4.QtGui import QPushButton, QTableWidget
from PyQt4.Qt import QApplication
window = QApplication(sys.argv)
class myTable(QTableWidget):
class MyCustomEditButton(QPushButton):
def __init__(self, i, name):
self.i = i
super().__init__(name)
self.clicked.connect(self.slot_pressed)
def slot_pressed(self):
window.tableWidget.StartStop(self.i)
def __init__(self):
super().__init__()
self.data = [
["1 строка"],
["2 строка"],
["3 строка"],
["4 строка"],
["5 строка"]
]
self.datacount = len(self.data)
self.setColumnCount(len(self.data[0])+1)
self.setRowCount(self.datacount)
for i in range(self.datacount):
btn = self.MyCustomEditButton(i, "Edit")
self.data0 = str(self.data[i][0])
self.setItem(i, 0, QtGui.QTableWidgetItem(self.data0))
self.setCellWidget(i, 1, btn)
def StartStop(self, bb):
print(bb)
window.tableWidget = myTable()
window.tableWidget.show()
window.exec()