Python/Pyside: Own QFileIconProvider implementation fails with no exceptions thrown -


i tried create own qfileiconprovider class, want use qfilesystemmodel. ended code:

class seiconprovider(qtgui.qfileiconprovider):  def __init__(self):     qtgui.qfileiconprovider.__init__(self)      self.rsfileicon = qtgui.qicon(':images/rs-file.png')     self.otherfileicon = qtgui.qicon(':images/newfile.png')     self.foldericon = qtgui.qicon(':images/openfolder.png')  def icon(self, type):     if type == self.file:         return self.rsfileicon     if type == self.folder:         return self.foldericon      return self.otherfileicon  def icon(self, info):     if info.isfile():         return self.otherfileicon     if info.isdir():         return self.foldericon     return self.otherfileicon  def type(self, info):     if info.isdir():         return 'directory'     return 'file'  class folderview(qtgui.qtreeview):      def __init__(self):         qtgui.qtreeview.__init__(self)          self.createcomponents()         self.createlayout()      def createcomponents(self):         self.model = qtgui.qfilesystemmodel()         self.model.seticonprovider(seiconprovider())         self.setmodel(self.model)      def createlayout(self):         self.setheaderhidden(true) 

now problem not no icons displayed in treeview, code doesn't throw exceptions. know doing wrong?

i solved problem myself now....kinda :d

i used go way , wrote own qfilesystemmodel class. have overwritten data method , returned own icons. code looks following:

class sefilesystemmodel(qtgui.qfilesystemmodel):  def __init__(self):     qtgui.qfilesystemmodel.__init__(self)     self.fileendpattern = re.compile("^.*\.(\w{2,4})$")  def data(self, index, role):     if index.column() == 0 , role == qtcore.qt.decorationrole:         if self.fileendpattern.match(index.data()) not none:             if index.data().endswith('rs'):                 return qtgui.qicon(':icons/rs-file.png')             return qtgui.qicon(':icons/newfile.png')          return qtgui.qicon(':icons/openfolder.png')      return super(sefilesystemmodel, self).data(index, role)  class folderview(qtgui.qtreeview):      def __init__(self):         qtgui.qtreeview.__init__(self)          self.createcomponents()      def createcomponents(self):         self.model = sefilesystemmodel()         self.setmodel(self.model) 

if knows, why original code wasn't working, still thankful answer :)


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -