Foros del Web » Programando para Internet » Python »

PyQt4 agregar alemento a una lista...

Estas en el tema de PyQt4 agregar alemento a una lista... en el foro de Python en Foros del Web. Este es el codigo que tengo hecho: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Python: Ver original # -*- coding: utf-8 -*-   # Form implementation generated from reading ...
  #1 (permalink)  
Antiguo 17/08/2010, 15:24
 
Fecha de Ingreso: abril-2010
Ubicación: Rosario
Mensajes: 1.850
Antigüedad: 14 años
Puntos: 228
PyQt4 agregar alemento a una lista...

Este es el codigo que tengo hecho:


Código Python:
Ver original
  1. # -*- coding: utf-8 -*-
  2.  
  3. # Form implementation generated from reading ui file 'ventana.ui'
  4. #
  5. # Created: Tue Aug 17 17:17:14 2010
  6. #      by: PyQt4 UI code generator 4.7.3
  7. #
  8. # WARNING! All changes made in this file will be lost!
  9. #from qt import *
  10. from PyQt4 import QtCore, QtGui
  11.  
  12. class Ui_MainWindow(object):
  13.     def setupUi(self, MainWindow):
  14.         MainWindow.setObjectName("MainWindow")
  15.         MainWindow.resize(800, 600)
  16.         self.centralwidget = QtGui.QWidget(MainWindow)
  17.         self.centralwidget.setObjectName("centralwidget")
  18.         self.pushButton = QtGui.QPushButton(self.centralwidget)
  19.         self.pushButton.setGeometry(QtCore.QRect(80, 50, 105, 24))
  20.         self.pushButton.setObjectName("pushButton")
  21.         self.label = QtGui.QLabel(self.centralwidget)
  22.         self.label.setGeometry(QtCore.QRect(350, 70, 271, 16))
  23.         self.label.setObjectName("label")
  24.         self.listView = QtGui.QListView(self.centralwidget)
  25.         self.listView.setGeometry(QtCore.QRect(100, 180, 256, 192))
  26.         self.listView.setObjectName("listView")
  27.         MainWindow.setCentralWidget(self.centralwidget)
  28.         self.menubar = QtGui.QMenuBar(MainWindow)
  29.         self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
  30.         self.menubar.setObjectName("menubar")
  31.         MainWindow.setMenuBar(self.menubar)
  32.         self.statusbar = QtGui.QStatusBar(MainWindow)
  33.         self.statusbar.setObjectName("statusbar")
  34.         MainWindow.setStatusBar(self.statusbar)
  35.         lvi = QtGui.QListView.QListViewItem(self.listView)
  36.         lvi.setText(0,"hola mundo")
  37.         self.retranslateUi(MainWindow)
  38.         QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), MainWindow.close)
  39.         QtCore.QMetaObject.connectSlotsByName(MainWindow)
  40.  
  41.     def retranslateUi(self, MainWindow):
  42.         MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
  43.         self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
  44.         self.label.setText(QtGui.QApplication.translate("MainWindow", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
  45.  
  46.  
  47. if __name__ == "__main__":
  48.     import sys
  49.     app = QtGui.QApplication(sys.argv)
  50.     MainWindow = QtGui.QMainWindow()
  51.     ui = Ui_MainWindow()
  52.     ui.setupUi(MainWindow)
  53.     MainWindow.show()
  54.     sys.exit(app.exec_())

Estoy teniendo problema en esta linea:

lvi = QListViewItem(self.listView)

Vi en muchas paginas que asi cargan elementos a las listas, pero a mi no me funciona. Me dice "NameError: global name 'QListViewItem' is not defined"

Veo que no ha sido cargado ese modulo, pero como lo hago o donde lo encuentro.
  #2 (permalink)  
Antiguo 18/08/2010, 00:31
 
Fecha de Ingreso: junio-2010
Mensajes: 29
Antigüedad: 13 años, 10 meses
Puntos: 0
Respuesta: PyQt4 agregar alemento a una lista...

MMMM la linea que da problemas es un poco diferente:

lvi = QtGui.QListView.QListViewItem(self.listView)

Y segun la documentacion que miro no existe QListVeiwItem:http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html[

Saludos
  #3 (permalink)  
Antiguo 18/08/2010, 09:11
 
Fecha de Ingreso: abril-2010
Ubicación: Rosario
Mensajes: 1.850
Antigüedad: 14 años
Puntos: 228
Respuesta: PyQt4 agregar alemento a una lista...

Pasa que pegue el codigo, depsues de hacer muchas pruebas..pero en unos ejemplos vi que lo hacian asi....

Tenes idea como se agrega elementos?
  #4 (permalink)  
Antiguo 18/08/2010, 11:57
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: PyQt4 agregar alemento a una lista...

Según cómo estás importando las clases:

QtGui.QListView.QListViewItem() <-- MAL
QListViewItem() <-- MAL
QtGui.QListViewItem() <-- BIEN

Pero el problema no es ese. QListViewItem es una clase de Qt3, no existe en Qt4 y se renombró como Q3ListViewItem para mantener compatibilidad.
En Qt4 usas QListWidget y QListWidgetItem (ver http://doc.trolltech.com/4.6/model-v...nvenience.html)

Aunque la verdadera raíz de tu problema es que no estás usando el QtCreator (QtDesigner), y estás creando la interfaz a mano Evalúa tus necesidades, y si realmente te vale la pena dedicarle tiempo a la interfaz.


Saludos.
  #5 (permalink)  
Antiguo 18/08/2010, 12:30
 
Fecha de Ingreso: abril-2010
Ubicación: Rosario
Mensajes: 1.850
Antigüedad: 14 años
Puntos: 228
Respuesta: PyQt4 agregar alemento a una lista...

Es que use QtCreator (QtDesigner), para crear ese codigo. El tema era para agregar elementos a la lista en momento de ejecucion.

Lo voy a probar y te cuento. Se ve que estaba usando la lista incorrecta!
  #6 (permalink)  
Antiguo 18/08/2010, 12:36
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: PyQt4 agregar alemento a una lista...

Tendría que haberme dado cuenta mirando los comentarios al principio del archivo
  #7 (permalink)  
Antiguo 18/08/2010, 12:49
 
Fecha de Ingreso: abril-2010
Ubicación: Rosario
Mensajes: 1.850
Antigüedad: 14 años
Puntos: 228
Respuesta: PyQt4 agregar alemento a una lista...

Ya lo probe, y funciono!! Muchas Gracias...

Etiquetas: lista, pyqt
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:36.