python - How to create columns header and its labels with QTableView -
the code below creates simple qtableview
header , 3 qstandarditem
s. question: how make header have 3 columns labeled "column 0", 'column 1" , "column 3"?
import os,sys pyqt4 import qtcore, qtgui app=qtgui.qapplication(sys.argv) class window(qtgui.qtableview): def __init__(self): super(window, self).__init__() header=qtgui.qheaderview(qtcore.qt.horizontal, self) self.sethorizontalheader(header) model=qtgui.qstandarditemmodel() in range(3): model.appendrow(qtgui.qstandarditem('item %s'%i)) self.setmodel(model) self.show() window=window() sys.exit(app.exec_())
use
model = qtgui.qstandarditemmodel(0,3) # 3 columns model.sethorizontalheaderlabels( [ "column 0", "column 1", "column 3"] )
Comments
Post a Comment