PDA

View Full Version : PyQt Vertical Header Icons?



jkrienert
18th January 2015, 13:57
Hoping to emplace an (repetitive) icon for each vertical header (row).
Currently the header 'box' is empty; without any text - yet efforts to set via headerData() function in AbstractTableModel do not seem to work.

Below is the current non-functioning script(s):

def headerData(self,section,orientation,role):
if role != Qt.DisplayRole:
return
if orientation == Qt.Vertical and role == Qt.DecorationRole:
return QtGui.QIcon(r'C:\Program Files\QGIS Brighton\apps\qgis\python\plugins\GraphicGroundwat er\buttons\zoomAndDrag.png')

if orientation == Qt.Horizontal:
return self.header[section]

Thousand thanks for any clues.

jefftee
19th January 2015, 23:14
You are returning if the role is not Qt.DisplayRole, which means your next if statement can never be true.

jkrienert
19th January 2015, 23:31
jthomps,
Ridiculous I didn't realize that. Thank you.
The following got things working (although I suppose the first if-pass statement isn't all together necessary):

def headerData(self,section,orientation,role):
if role != Qt.DisplayRole:
pass
if orientation == Qt.Vertical and role == Qt.DecorationRole:
return QtGui.QIcon(r'...\buttons\zoomAndDrag.png')
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.header[section]

Again, a thousand thanks jthomps.