[PyKDE] QListView

Luis M. Gallardo D. gluis at alsuites.com
Wed Aug 30 18:46:42 BST 2000


	Hi. I've tried to use a QListView, but I had some problems. I'm going
to explain what I'm doing. I'm making a application that allow me list a
directory from my PC and from a HP calculator (using Kermit protocol).
I'm going to show my Python Code:

---

#!/usr/bin/env python

from kde import *
import string, commands, sys, calendar, time, StringIO

class MakeQListView(QListView):
 def __init__(self,parent):
  QListView.__init__(self,parent)
  self.files=[]

class ApplicationWindow(KTMainWindow):
 def __init__(self, *args):
  apply(KTMainWindow.__init__,(self,) + args)


  self.DirPc= MakeQListView(self)
  self.DirPc.resize(440,200)
  self.DirPc.move(10,53)

  self.DirPc.addColumn("Name")
  self.DirPc.addColumn("Size")
  self.DirPc.addColumn("Owner")
  self.DirPc.addColumn("Attributes")

  self.DirPc.show()

  self.DirPc.connect(self.DirPc, SIGNAL("selectionChanged()"),
self.selected)
#  self.DirPc.connect(self.DirPc, SIGNAL("doubleClicked()"),
self.selected)

# Here I've tried to connect dobleClicked() signal with DirPC
(QListView), but I've able to do it.

  self.Pc= commands.getoutput('pwd')

  self.DirectoryPc(self.Pc)

 def DirectoryPc(self, Path):
  dir= commands.getoutput('ls -l')
  dir= string.split(dir,"\n")
  dir= dir[1:]

  self.DirPc.files= []

  d= QListViewItem(self.DirPc, "..", None, None, None)
  self.DirPc.files.append(d)

  for x in dir:
   x= string.split(x)
   Info= QFileInfo(x[8])
   d= QListViewItem(self.DirPc, x[8], x[4], x[2]+' '+x[3], x[0])


   if Info.isDir():
    p = QPixmap('/opt/kde/share/icons/mini/folder.xpm')
    d.setPixmap(0,p)
   else:
    p = QPixmap('/opt/kde/share/icons/mini/document.xpm')
    d.setPixmap(0,p)

   self.DirPc.files.append(d)


  self.DirPc.setSorting(3,0)
  print self.DirPc.childCount()
  return


 def selected(self):
  if self.DirPc.currentItem().text(0) == "..":
   self.Pc= commands.getoutput('cd ..')
   print self.Pc
   self.Pc= commands.getoutput('pwd')
   print self.Pc
   self.DirPc.clear()
   self.DirectoryPc(self.Pc)


a = KApplication(sys.argv)
mw = ApplicationWindow()
mw.setMinimumSize(650,470)
mw.setMaximumSize(650,470)
mw.setGeometry(1,1,200,120)
a.setMainWidget(mw)
mw.setCaption('QListViewProblem')
mw.show()
a.connect(a, SIGNAL('lastWindowClosed()'), a.quit)
a.exec_loop()


---

Problems:
	
1) I have tried to connect dobleClicked() signal with DirPC (QListView),
but I've able to do it. Qt Documentation specifies that there is a
dobleClicked() signal, but when I include this signal I get a "No such
signal QListView::doubleClicked()"  message.

2) When I include selectionChanged() signal, I can detect when a change
occur. This way I can know when ".." item is clicked and I've connected
QListView to a function (selected()) for reload current directory, but
when I try to delete all items with .clear() I've got a segmentation
fault.


Please a little hint.


---
Luis Gallardo
Caracas - Venezuela





More information about the PyQt mailing list