[PyQt] Mac does not pass back QIcon from data() method in a model/view

bvz bvz at c381.com
Sat Oct 3 08:44:13 BST 2009

I have just noticed this little oddity:

I have a data() method inside a QAbstractTableModel subclass.  This method
is supposed to pass back an icon for a QTableView to display when the role
Qt.DecorationRole is used.

On the Mac it will only return the icon if I use:
return QtGui.QIcon(paramObj.get_icon())

On Linux, it will only work if I use:
return QtCore.QVariant(paramObj.get_icon())

Am I doing something wrong, or is this just a little weirdness that I should
code around?

Here is the actual code, currently set up to run on my Mac:

    def data(self, index, role=QtCore.Qt.DisplayRole):
        Returns the text or formatting for a particular cell, depending on
        role supplied.
        if not index.isValid() or not (0 <= index.row() < self.rowCount()):
            return QtCore.QVariant()
        #get the light, and from that, get the parameter requested
        lightObj = self.get_light_at_index(index.row())
        paramObj = self.get_parameter_at_index(lightObj, index.column())

        if role == QtCore.Qt.DisplayRole:
            return QtCore.QVariant(paramObj.get_formatted_display_value())
        elif role == QtCore.Qt.TextColorRole:
            return QtCore.QVariant(paramObj.get_text_color())
        elif role == QtCore.Qt.TextAlignmentRole:
            return QtCore.QVariant(paramObj.get_text_alignment())
        elif role == QtCore.Qt.FontRole:
            return QtCore.QVariant(paramObj.get_text_font())
        elif role == QtCore.Qt.DecorationRole:
            return QtGui.QIcon(paramObj.get_icon())
#             return QtCore.QVariant(paramObj.get_icon())

        elif role == QtCore.Qt.BackgroundColorRole:
            return QtCore.QVariant(paramObj.get_cell_color())
        return QtCore.QVariant()

View this message in context: http://www.nabble.com/Mac-does-not-pass-back-QIcon-from-data%28%29-method-in-a-model-view-tp25726451p25726451.html
Sent from the PyQt mailing list archive at Nabble.com.

More information about the PyQt mailing list