Issue
I have a TreeView that I'm unable to see headers for. In my class definition for the QAbstractItemModel, I'm implementing the headerData() function as follows:
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
if role != QtCore.Qt.DisplayRole:
return '' # empty string since QVariant isn't in PySide
if orientation == QtCore.Qt.Horizontal:
return 'TEST'
return ''
If I implement headerData(), the header simply disappears. Without it, I just get a generic horizontal header with numeric labels (1,2,3, etc.). Can anyone explain what's happening here?
Solution
According to the documentation:
PySide.QtCore.QAbstractItemModel.headerData(section, orientation[, role=Qt.DisplayRole])
Parameters:
section – PySide.QtCore.intorientation – PySide.QtCore.Qt.Orientation
role – PySide.QtCore.int Return type: object
This returns an int type, but Display role is part of the QtCore.Qt.ItemDataRole enumeration
To solve I propose the following code:
def headerData(self, section, orientation, role=0):
role = QtCore.Qt.ItemDataRole(role)
if role != QtCore.Qt.DisplayRole:
return None
if orientation == QtCore.Qt.Horizontal:
return "Test"
return None
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.