title: How can I add and remove items properly in a qlistview?
body: <p>I am trying to do this in both qlistview and qlistwiget adding is ok but removing, I can't figure out even after reading the docs. If someone could please shed some light on how to do this, I will greatly appreciate it. Here's my code below: </p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  from PyQt4 import QtCore, QtGui
  
  
  class Try(QtGui.QDialog):
      def __init__(self):
          super(Try, self).__init__()
          self.setWindowTitle("Trying stuff")
          self.list_view = QtGui.QListView(self)
          self.lview = QtGui.QListWidget(self)
          self.EditText = QtGui.QLineEdit()
          self.EditText.setPlaceholderText("add stuff")
          self.EditText.setMaximumWidth(200)
          self.setWindowFlags(QtCore.Qt.Window)
          self.model = QtGui.QStandardItemModel(self.list_view)
          self.resize(600, 500)
          self.font = QtGui.QFont()
          self.font.setBold(True)
          self.font2 = QtGui.QFont()
          self.font2.setBold(False)
          palette = QtGui.QPalette()
          palette.setColor(QtGui.QPalette.Foreground, QtCore.Qt.red)
          self.label = QtGui.QLabel()
          self.buttonRemove = QtGui.QPushButton()
          self.buttonAdd = QtGui.QPushButton()
          self.buttonCommit = QtGui.QPushButton()
          self.buttonRemove.setText("Remove from list")
          self.buttonRemove.clicked.connect(self.removeItems)
          self.buttonAdd.setText("Add to list")
          self.buttonAdd.clicked.connect(self.addItems)
          self.buttonCommit.setText("print all item in list")
  
          horizontalLayout = QtGui.QHBoxLayout()
          horizontalLayout.addWidget(self.EditText)
          horizontalLayout.addWidget(self.buttonAdd)
  
          horizontalLayout.setAlignment(QtCore.Qt.AlignRight)
          horizontalLayout2 = QtGui.QHBoxLayout()
          horizontalLayout2.addWidget(self.buttonRemove)
          horizontalLayout2.addWidget(self.buttonCommit)
          horizontalLayout2.setAlignment(QtCore.Qt.AlignRight)
  
          verticalLayout = QtGui.QVBoxLayout(self)
          verticalLayout.addLayout(horizontalLayout)
          verticalLayout.addWidget(self.list_view)
          verticalLayout.addWidget(self.lview)
          verticalLayout.addWidget(self.label)
          verticalLayout.addLayout(horizontalLayout2)
  
  
      def addItems(self):
          x = self.EditText.text()
          self.lview.addItem(x)
          self.lview.setAutoScroll(True)
          item = QtGui.QStandardItem(x)
          item.setCheckable(True)
          item.setCheckState(QtCore.Qt.Unchecked)
          self.model.appendRow(item)
          self.list_view.setModel(self.model)
          self.EditText.clear()
  
      def removeItems(self):
          x = self.EditText.text()
          item = QtGui.QStandardItem(x)
          todelete = self.list_view.selectionModel().currentIndex().data().toString()
          print todelete
          self.model.removeRow(todelete)
          self.lview.takeItem(item.row())
          #self.model.removeRow(item.row())
  
          self.list_view.setModel(self.model)
          self.EditText.clear()
  
  if __name__ == '__main__':
      app = QtGui.QApplication(sys.argv)
      t = Try()
      t.show()
      sys.exit(app.exec_())
  </code></pre>