[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] Subclassing QIcon does not work in item views
From:       Charles <peacech () gmail ! com>
Date:       2015-08-18 2:37:32
Message-ID: CABthHP_yadZ=Q3R7eF2j9hLxWPee57p3wVe=C2AF4BTCVMUBYw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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?

[Attachment #5 (text/html)]

<div dir="ltr"><div><div><div><div><div>Hi,<br><br></div>I subclass QIcon to find the \
icon location from a name<br><br>class Icon(QIcon):<br>    def __init__(self, \
name):<br>        # find icon for name<br>        \
super().__init__(found)<br><br></div>It works if I use it for the window \
icon<br><br>class MainWindow(QMainWindow):<br>    def __init__(self):<br>        \
super().__init__()<br>        \
self.setWindowIcon(Icon(&#39;window&#39;))<br><br></div>But it does not work (showing \
a blank icon) if I use it for DecorationRole in an itemviews model<br><br>class \
Model(QAbstractItemModel):<br>    def data(self, index, role):<br>        if not \
index.isValid():<br>            return None<br>        if column == 0:<br>            \
if role == Qt.DecorationRole:<br>                return \
Icon(&#39;item&#39;)<br><br></div>The icon works if I use QIcon directly<br><br>class \
Model(QAbstractItemModel):<br>    def data(self, index, role):<br>        if not \
index.isValid():<br>            return None<br>        if column == 0:<br>            \
if role == Qt.DecorationRole:<br>                return \
QIcon(&#39;res/item.png&#39;)<br><br></div>Any pointer on why subclassing QIcon does \
not work on this case?<br></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic