I want to add my data to a table using pyqt in python. I found that I should use setItem() function to add data to a QTableWidget and give it the row and column number and a QTableWidgetItem. I did it but when I want to display the table, it's completely empty.
Maybe I made a silly mistake but please help me.
Here is my code:
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_())