[PyQt] Subclassing QIcon does not work in item views

Charles peacech at gmail.com
Tue Aug 18 03:37:32 BST 2015


Hi,

I subclass QIcon to find the icon location from a name

class Icon(QIcon):
    def __init__(self, name):
        # find icon for name
        super().__init__(found)

It works if I use it for the window icon

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowIcon(Icon('window'))

But it does not work (showing a blank icon) if I use it for DecorationRole
in an itemviews model

class Model(QAbstractItemModel):
    def data(self, index, role):
        if not index.isValid():
            return None
        if column == 0:
            if role == Qt.DecorationRole:
                return Icon('item')

The icon works if I use QIcon directly

class Model(QAbstractItemModel):
    def data(self, index, role):
        if not index.isValid():
            return None
        if column == 0:
            if role == Qt.DecorationRole:
                return QIcon('res/item.png')

Any pointer on why subclassing QIcon does not work on this case?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150818/f4252468/attachment.html>


More information about the PyQt mailing list