[PyQt] Model/View

Andreas Pakulat apaku at gmx.de
Thu Nov 8 17:06:48 GMT 2007


On 08.11.07 17:29:49, Sun Wukong wrote:
> Hello,
> 
> I'm a PyQt newbie, trying to implement the following exemple
> http://doc.trolltech.com/4.0/qt4-interview.html
> in Python.
> 
> Unfortunatly, nothing appear in the window but its title.
> 
> Thanks for your help.
> Sw
> 
> Here's my code :
> 
> import sys
> >from PyQt4 import QtGui
> >from PyQt4 import QtCore
> 
> 
> class ZeTest(QtGui.QMainWindow):
>     def __init__(self, parent=None):
>         QtGui.QMainWindow.__init__(self, parent)
> 
>         splitter = QtGui.QSplitter()
>         model = QtGui.QDirModel()
>         arbre = QtGui.QTreeView(splitter)
> 
>         arbre.setModel(model)
>         arbre.setRootIndex(model.index(QtCore.QDir.currentPath()))
> 
>         QtCore.qDebug("Current Dir : " + str( QtCore.QDir.currentPath()))
> 
>         maliste = QtGui.QListView(splitter)
>         maliste.setModel(model)
>         maliste.setRootIndex(model.index(QtCore.QDir.currentPath()))
> 
>         maselection = QtGui.QItemSelectionModel(model)
>         arbre.setSelectionModel(maselection)
>         maliste.setSelectionModel(maselection)
> 
>         self.setWindowTitle("Two views onto the same directory model")

At this point the splitter, model and arbre are all garbage collected
because there's no reference anymore to them. Store them as instance
variables by using self.splitter etc.

Andreas

-- 
Your object is to save the world, while still leading a pleasant life.


More information about the PyQt mailing list