Creation de slots (PyQT4)

Creation de slots (PyQT4) - Python - Programmation

Marsh Posté le 23-04-2010 à 16:45:05    

Bonjour,
 
j'ai rencontre un probleme lors de la creation de slots.
 
En effet, souhaitant creer un slot lie a un bouton, j'ai bien ajoute un slot a ma MainWindow, mais lorsque j'ai tente de l'implementer (Formulaire -> Visualizer le code), j'ai obtenu l'erreur contenu dans l'image suivante:
 
http://www.developpez.net/forums/attachments/p61488d1272032996/autres-langages/python-zope/gui/pyqt/creation-slots-pyqt4/error.png/
 
Pourtant j'ai bien un dossier uic ici: C:\Python26\Lib\site-packages\PyQt4\uic
 
Si quelqu'un a une idee... merci a vous !!!
 
 
note: je suis sous Windows XP, avec Python 2.6.2 et PyQT4.

Reply

Marsh Posté le 23-04-2010 à 16:45:05   

Reply

Marsh Posté le 13-05-2010 à 22:16:49    

Tu voudrais pas nous poster ton code ???
 
Essaye de ton coté celui-là

Code :
  1. #!/usr/bin/env python
  2. # coding: UTF-8 -*-
  3.  
  4. import sys
  5. try:
  6.     from PyQt4.QtCore import *
  7.     from PyQt4.QtGui import *
  8. except:
  9.     import time
  10.     for i in range(10):
  11.         print "PyQt non installé - A vérifier (%d/10)" % (i + 1)
  12.     time.sleep(5)
  13.     sys.exit(1)
  14.  
  15. class QtAppli(QApplication):
  16.     "Fenêtre de l'application"
  17.  
  18.     # Constructeur fenêtre
  19.     def __init__(self,
  20.             argv):
  21.  
  22.         # Message de contrôle
  23.         print "QtAppli (qt v%s, pyqt_v%s)" % (QT_VERSION_STR, PYQT_VERSION_STR)
  24.  
  25.         # Appel constructeur de l'objet hértié
  26.         QApplication.__init__(self, argv)
  27.  
  28.         # Widget principale
  29.         self.__mainWid=QMainWindow()
  30.         self.__mainWid.setCentralWidget(QWidget(self.__mainWid))
  31.         self.__mainWid.statusBar()
  32.  
  33.         # Titre
  34.         self.__mainWid.setWindowTitle(
  35.             QString.fromUtf8("Vérification Qt (v%s)" % QT_VERSION_STR)
  36.         )
  37.  
  38.         # Un espace de rangement
  39.         mainLayout=QVBoxLayout(self.__mainWid.centralWidget())
  40.  
  41.         # Le bouton
  42.         btn=QPushButton(
  43.             QString.fromUtf8("Surtout ne pas cliquer là !!!" )
  44.         )
  45.         self.connect(btn, SIGNAL("clicked()" ), self.slotAction)
  46.         mainLayout.addWidget(btn)
  47.  
  48.         # Le bouton version
  49.         ver=QPushButton(
  50.             QString.fromUtf8("A propos de Qt" )
  51.         )
  52.         self.connect(ver, SIGNAL("clicked()" ), self.slotQt)
  53.         mainLayout.addWidget(ver)
  54.  
  55.         # Pour quitter
  56.         quit=QPushButton(
  57.             QString.fromUtf8("Quitter" )
  58.         )
  59.         self.connect(quit, SIGNAL("clicked()" ), self.__mainWid, SLOT("close()" ))
  60.         mainLayout.addWidget(quit)
  61.     # __init__()
  62.  
  63.     # Affichage et lancement application
  64.     def run(self):
  65.         self.__mainWid.show()
  66.         self.exec_()
  67.     # run()
  68.  
  69.     # Slot qui affiche une fenêtre avec un texte
  70.     def slotAction(self):
  71.         print "test"
  72.  
  73.         dial=QDialog(self.__mainWid.centralWidget())
  74.         dial.setModal(True)
  75.         dial.setWindowTitle(
  76.             QString.fromUtf8("Félicitations, Qt fonctionne parfaitement !!!" )
  77.         )
  78.  
  79.         mainLayout=QVBoxLayout(dial)
  80.  
  81.         lab=QLabel(
  82.             QString.fromUtf8("<center><font size='+5'>C'était écrit <u><font color='red'>SURTOUT</font></u> ne pas cliquer !!!</font></center>" )
  83.         )
  84.         mainLayout.addWidget(lab)
  85.  
  86.         btn=QPushButton(
  87.             QString.fromUtf8("Félicitations, Qt fonctionne parfaitement !!!" )
  88.         )
  89.         btn.connect(btn, SIGNAL("clicked()" ), dial, SLOT("close()" ))
  90.         mainLayout.addWidget(btn)
  91.         dial.show()
  92.     # slotAction()
  93.  
  94.     # Slot qui affiche la version de Qt
  95.     def slotQt(self):
  96.         print "qt"
  97.  
  98.         # Fenêtre "A propos de Qt"
  99.         QMessageBox.aboutQt(
  100.             self.__mainWid,
  101.             "à propos de Qt...",
  102.         )
  103.     # slotQt()
  104. # class QtAppli
  105.  
  106. Appli=QtAppli(sys.argv)
  107. Appli.run()



---------------
Vous ne pouvez pas apporter la prospérité au pauvre en la retirant au riche.
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed