In Pyqt, I am trying to make the QHeaderView of a QTableWidget respond to right mouse clicks. I have subclassed QHeaderView and i have overloaded the mousePressEvent.
Then i can set it as as the header of my custom QTableWidget, the DataTable class. However i don't understand how to set the labels of the header.
Thanks for helping!
Here is some code.
class Header( QtGui.QHeaderView ):
    def __init__ ( self, parent ):
        QtGui.QHeaderView.__init__( self, QtCore.Qt.Vertical, parent=parent )
    def mousePressEvent( self, event ):
        if event.button() == QtCore.Qt.RightButton:
            do_stuff()
class DataTable( QtGui.QTableWidget ):
    def __init__ ( self ):
        QtGui.QTableWidget.__init__( self )
        self.setShowGrid(True)
        self.header = Header( parent = self )
        self.header.setClickable(True)
        self.setHorizontalHeader( self.header )
    def set_header( self, labels ):
        ???
				
                        
Short answer:
The QTableWidget has a function called "setHorizontalHeaderLabels", simply supply your headers to it. Like so:
I would have added this as a comment to pedrotech, but I don't have enough rep for comments.