I have been searching around the fourm for a way to make the QHeadView editable when double clicked. The best link I found had only had and example file and the link was broken. I have been searching on and off for two weeks or so.

Anyway as I stated before I am trying to make a QHeaderView that is editable when double clicked. The best I have gotten it to create a line edit box and un hide it when a section is clicked. However none of the close edit signals are triggered when editting is done so I have no good way to pass the info of what was changed back to the dataset. I know that I need to use a delegate I just don't know how. I am writting in Python but at this point I will take help in any programming language.

Below is a sample of what I have come up with

Qt Code:
  1. class MyHeaderView(QtGui.QHeaderView):
  2.  
  3. def __init__(self,orientation,dataset,parent=None):
  4. super(MyHeaderView, self).__init__(orientation,parent)
  5. self.data = dataset
  6. # This block sets up the edit line by making setting the parent
  7. # to the Headers Viewport.
  8. self.line = QtGui.QLineEdit(parent=self.viewport()) #Create
  9. self.line.setAlignment(QtCore.Qt.AlignTop) # Set the Alignmnet
  10. self.line.setHidden(True) # Hide it till its needed
  11.  
  12. self.sectionedit = 0
  13.  
  14. # Connects to double click
  15. self.sectionDoubleClicked.connect(self.editHeader)
  16. self.line.editingFinished.connect(self.setHeaderData)
  17.  
  18. def editHeader(self,section):
  19.  
  20. # This block sets up the geometry for the line edit
  21. edit_geometry = self.line.geometry()
  22. edit_geometry.setWidth(self.sectionSize(section))
  23. edit_geometry.moveLeft(self.sectionViewportPosition(section))
  24. self.line.setGeometry(edit_geometry)
  25.  
  26. self.line.setHidden(False) # Make it visiable
  27. self.line.setFocus()
  28. self.sectionedit = section
  29.  
  30. def setHeaderData(self, section, orientation, value,
  31. role = QtCore.Qt.EditRole):
  32. # Update dataset
  33. pass
To copy to clipboard, switch view to plain text mode