By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

how to delete the rows with the delete button and how to edit with edit button

P: 1
the code that am sharing is just working for the add button only would you help me in the delete and edit button....thanks so much


Expand|Select|Wrap|Line Numbers
  1. from PyQt4 import QtGui , QtCore
  2. class Example ( QtGui.QWidget ):
  3.     row = 0
  4.     def __init__ ( self ):
  5.         super ( Example , self ). __init__ ()
  6.         self.setGeometry (300 , 300 , 350 , 250)
  7.         self.setWindowTitle ( " names " )
  8.         #self.menubar()
  9.         self.initData ()
  10.         self.initUI ()
  11.         row=0;
  12.         col=0;
  13.     def initData ( self ):
  14.         data = ("David otewa","meshack Otewa" )
  15.         self.model = QtGui.QStandardItemModel (12 , 1)
  16.  
  17.         col = 0
  18.         for i in data :
  19.             item = QtGui.QStandardItem(str((i)))
  20.             self.model.setItem(self.row,col,item )
  21.             self.row = self.row + 1
  22.     def initUI ( self ):
  23.         lv = QtGui . QListView( self )
  24.         lv.setModel(self.model )
  25.  
  26.         layout=QtGui.QVBoxLayout()
  27.         layout.addWidget(lv)
  28.         col=0
  29.         row=0
  30.         add=QtGui.QPushButton("Add",self)
  31.         add.move(265,30)
  32.  
  33.         self.connect(add, QtCore.SIGNAL('clicked()'), self.showDialog)
  34.  
  35.         delete=QtGui.QPushButton("Delete",self)
  36.         delete.move(265,60)
  37.  
  38.         edit=QtGui.QPushButton("Edit",self )
  39.         edit.move(265,90)
  40.  
  41.  
  42.  
  43.     def showDialog(self):
  44.  
  45.         text, ok = QtGui.QInputDialog.getText(self, 'Names', 
  46.                 'Enter your name:')
  47.  
  48.         if ok:
  49.             name=str(text)
  50.             self.add(name)
  51.  
  52.     def add(self,name):
  53.         data=str(name)
  54.         col=0
  55.         if data != ("") :
  56.             item = QtGui.QStandardItem(str((data)))
  57.             self.model.setItem(self.row,col,item )
  58.             self.row = self.row + 1
  59.  
  60.  
  61. app=QtGui.QApplication([])
  62. ex=Example()
  63. ex.show()
  64. app.exec_()
Sep 8 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.