class Table(QtGui.QDialog):
def __init__(self, parent=None):
super(Table, self).__init__(parent)
layout = QtGui.QGridLayout()
self.table = QtGui.QTableWidget()
self.table.setRowCount(20)
self.table.setColumnCount(3)
layout.addWidget(self.table)
self.enterDataInTable()
self.setLayout(layout)
def enterDataInTable(self):
for row in range(0,20):
for column in range(0,3):
self.table.setItem(row, column, QtGui.QTableWidgetItem("cell %s-%s"%(row+1,column+1)))
This code produces a table with 20 rows and 3 columns, the data within each one informs me of its location. I want to instead have my database column and row titles, including the information inside them. This will be using sqlite 3. How would I be able to insert the database here and connect it appropriately?
Qt has ready-to-use tablemodels that connect to a database.
Check
http://pyqt.sourceforge.net/Docs/PyQt4/qsqltablemodel.html
and the
site-packages\PyQt4\examples\sql
(that's where it's installed on my machine) folder in your PyQt installation.Well a better solution to solve this problem would be by using Model View Programming . Here is a solution using model view.