Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. with sqlite3.connect('database.db') as db:
  2. cursor=db.cursor()
  3. cursor.execute('select* from Item Order BY Name ASC')
  4. title = [cn[0] for cn in cursor.description]
  5. rows = [cn[0] for cn in cursor.description]
  6. cur=cursor.fetchall()
  7.  
  8.  
  9. layout = QtGui.QGridLayout()
  10. self.test = QtGui.QLineEdit('test') #This is just a test for printing text into the table and works fine.
  11.  
  12. self.table = QtGui.QTableWidget()
  13.  
  14. for rows in cur:
  15. print(rows[1]) #This is just a test to see if the data could be printed into python shell, which worked.
  16.  
  17.  
  18. #self.test2 = QtGui.QLineEdit(cur)
  19. #self.table.setVerticalHeaderLabels(rows)
  20.  
  21. self.table.setRowCount(3)
  22. self.table.setColumnCount(5)
  23. self.table.setHorizontalHeaderLabels(title) #This code works fine, the column headers are the ones from my database.
  24. #self.table.setVerticalHeaderItem(1,row)
  25.  
  26. layout.addWidget(self.table, 0, 0)
  27. self.table.setItem(0, 0, QtGui.QTableWidgetItem(self.test.text()))
  28. #self.table.setItem(1, 0, QtGui.QTableWidgetItem(self.test2.text()))
  29.  
  30. self.setLayout(layout)
  31.  
  32. cur=cursor.fetchall()
  33. for i,row in enumerate(cur):
  34. for j,val in enumerate(row):
  35. table.setItem(i, j, QtGui.QTableWidgetItem(str(val)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement