[PyKDE] How to use QHeaderView ?

Olivier Fournier o.fournier at perigord.com
Thu Mar 23 15:45:30 GMT 2006


Hi,

I don't understand how to use QheaderView in pyqt4:

I need to know when an user modify the witdh of a column so I think use 
the signal QHeaderView.sectionResized

So, I add to my TableView an QHeaderView:

import sys
from PyQt4 import QtCore, QtGui

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        
Form.resize(QtCore.QSize(QtCore.QRect(0,0,400,300).size()).expandedTo(Form.minimumSizeHint()))
       
        self.tableView = QtGui.QTableView(Form)
        self.tableView.setGeometry(QtCore.QRect(10,10,351,251))
        self.tableView.setObjectName("tableView")
       
        self.model = QtGui.QStandardItemModel( 2, 3 )
        self.tableView.setModel(self.model)
       
        self.headCol = QtGui.QHeaderView(QtCore.Qt.Horizontal)
        self.tableView.setHorizontalHeader( self.headCol )
       
        self.model.setHeaderData(0, QtCore.Qt.Horizontal, 
QtCore.QVariant("Col 1"))
        self.model.setHeaderData(1, QtCore.Qt.Horizontal, 
QtCore.QVariant("Col 2"))
        self.model.setHeaderData(2, QtCore.Qt.Horizontal, 
QtCore.QVariant("Col 3"))

        print self.headCol.count()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

But the Horizontal Header is hide
and print self.headCol.count() give 3
I don't understand how to use it

Could you help me?
Thank you for your help
Best regards

Olivier Fournier




More information about the PyQt mailing list