Quiero agregar mis datos a una tabla usando pyqt en python. Encontré que debería usar la función setItem()
para agregar datos a QTableWidget
y darle el número de fila y columna y un QTableWidgetItem
. Lo hice pero cuando quiero mostrar la tabla, está completamente vacía. Tal vez cometí un error tonto, pero por favor, ayúdenme. Aquí está mi código:Agregar datos a QTableWidget usando PyQt4 en Python
from PyQt4 import QtGui
class Table(QtGui.QDialog):
def __init__(self, parent=None):
super(Table, self).__init__(parent)
layout = QtGui.QGridLayout()
self.led = QtGui.QLineEdit("Sample")
self.table = QtGui.QTableWidget()
layout.addWidget(self.led, 0, 0)
layout.addWidget(self.table, 1, 0)
self.table.setItem(1, 0, QtGui.QTableWidgetItem(self.led.text()))
self.setLayout(layout)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
t = Table()
t.show()
sys.exit(app.exec_())