Skip to content

Instantly share code, notes, and snippets.

@oglops
Created February 15, 2016 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oglops/83d18c1713da33d79edf to your computer and use it in GitHub Desktop.
Save oglops/83d18c1713da33d79edf to your computer and use it in GitHub Desktop.
QTableView + QStandardItemModel
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Window(QMainWindow):
'This time I try to put the table populating code in main ui'
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.model = QStandardItemModel(5, 3)
table = QTableView()
table.setModel(self.model)
for n, key in enumerate(sorted(data.keys())):
self.model.setHorizontalHeaderItem(n, QStandardItem(key))
for m, value in enumerate(data[key]):
index = self.model.index(m, n)
self.model.setData(index, value)
self.setCentralWidget(table)
self.resize(350, 220)
def main(args):
app = QApplication(args)
window = Window()
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment