[PyQt] How to subclass a QTreeWidget?

Karlo Lozovina karlo.lozovina at gmail.com
Thu Jun 7 02:07:04 BST 2007


Hello everyone,

I'm trying here to subclass a QTreeWidget so I can implement some
custom methods for displaying and modifying data. In the wxPython
world approach similar to this worked for me, but now I'm getting an
error.

Here is the part where I initialize my custom QTreeWidget:

---------
self.mainControls = QtGui.QTabWidget(self.centralWidget)
self.mainControls.setObjectName("mainControls")

self.tabSongs = QtGui.QWidget()
self.tabSongs.setObjectName("tabSongs")

self.hboxlaySongs = QtGui.QHBoxLayout(self.tabSongs)
self.hboxlaySongs.setMargin(3)
self.hboxlaySongs.setSpacing(3)
self.hboxlaySongs.setObjectName("hboxlaySongs")

self.songsTreeView = SongsTreeView(self.tabSongs)
self.songsTreeView.setObjectName("songsTreeView")
self.hboxlaySongs.addWidget(self.songsTreeView)

self.mainControls.addTab(self.tabSongs, "Glazba")
---------

And this is the code for the SongsTreeView object:

---------
class SongsTreeView(QtGui.QTreeWidget):
    def __init__(self, parent):
        QtGui.QTreeWidget.__init__(parent)
---------

When I try to run the code I get the following mistake:

---------
Traceback (most recent call last):
  File "MBoss.py", line 54, in <module>
    boss_app = BossApp()
  File "MBoss.py", line 42, in __init__
    self.ui = BossMainWindow(self)
  File "/home/mosor/projects/mediatouch/mtouch/mboss/BossMainWindow.py",
line 33, in __init__
    self._initGui()
  File "/home/mosor/projects/mediatouch/mtouch/mboss/BossMainWindow.py",
line 61, in _initGui
    self.songsTreeView.setObjectName("songsTreeView")
RuntimeError: underlying C/C++ object has been deleted
[1]    25619 segmentation fault  python MBoss.py
---------

Now, what am I doing wrong :)? Is there another way to subclass a
QTreeWidget and customize it to my needs?
Any help greatly appreciated.

-- 
Karlo Lozovina - Mosor
"Parce mihi domine quia Dalmata sum."


More information about the PyQt mailing list