[Python-de] pyQt4 QPushButton und QtCore.SIGNAL("clicked()")

Uwe Wilske wnf at wlsoft.de
Mo Aug 4 16:36:11 CEST 2008


Hallo,

Kann mir jemand sagen, warum on_bb_Quelle_clicked() dreimal nacheinander 
ausgeführt wird, wenn ich einmal auf bb_Quelle klicke?

---------------------------------------------------------------------------

#!/usr/bin/env python
import sys
from PyQt4 import QtGui,QtCore
from am_main import Ui_Dialog as Dlg

class Download_Dlg(QtGui.QDialog, Dlg):
     def __init__(self):
         QtGui.QDialog.__init__(self)
         self.setupUi(self)
         self.ed_Quelle.setText('xxx')

         #Slots einrichen
         self.connect(self.bb_Quelle,QtCore.SIGNAL("clicked()"),
             self.on_bb_Quelle_clicked)

     def on_bb_Quelle_clicked(self):
         print 'Quellverzeichnis lesen'
         print self.objectName
         filename = QtGui.QFileDialog.getExistingDirectory(self,
            'Open File','/media')
         self.ed_Quelle.setText(filename)
         print filename


if __name__ == '__main__':
   app = QtGui.QApplication(sys.argv)
   dialog = Download_Dlg()
   dialog.show()
   sys.exit(app.exec_())

---------------------------------------------------------------------------

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'am_main.ui'
#
# Created: Mon Aug  4 16:16:53 2008
#      by: PyQt4 UI code generator 4.3.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_Dialog(object):
     def setupUi(self, Dialog):
         Dialog.setObjectName("Dialog")
 
Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,516,300).size()).expandedTo(Dialog.minimumSizeHint()))

         self.widget = QtGui.QWidget(Dialog)
         self.widget.setGeometry(QtCore.QRect(0,0,451,121))
         self.widget.setObjectName("widget")

         self.vboxlayout = QtGui.QVBoxLayout(self.widget)
         self.vboxlayout.setObjectName("vboxlayout")

         self.gb_Quelle = QtGui.QGroupBox(self.widget)
         self.gb_Quelle.setObjectName("gb_Quelle")

         self.ed_Quelle = QtGui.QLineEdit(self.gb_Quelle)
         self.ed_Quelle.setGeometry(QtCore.QRect(10,20,341,24))
         self.ed_Quelle.setObjectName("ed_Quelle")

         self.bb_Quelle = QtGui.QPushButton(self.gb_Quelle)
         self.bb_Quelle.setGeometry(QtCore.QRect(360,20,28,28))
         self.bb_Quelle.setObjectName("bb_Quelle")
         self.vboxlayout.addWidget(self.gb_Quelle)

         self.gb_Ziel = QtGui.QGroupBox(self.widget)
         self.gb_Ziel.setObjectName("gb_Ziel")

         self.ed_Ziel = QtGui.QLineEdit(self.gb_Ziel)
         self.ed_Ziel.setGeometry(QtCore.QRect(10,20,341,24))
         self.ed_Ziel.setObjectName("ed_Ziel")

         self.bb_Ziel = QtGui.QPushButton(self.gb_Ziel)
         self.bb_Ziel.setGeometry(QtCore.QRect(360,20,28,28))
         self.bb_Ziel.setObjectName("bb_Ziel")
         self.vboxlayout.addWidget(self.gb_Ziel)

         self.retranslateUi(Dialog)
         QtCore.QMetaObject.connectSlotsByName(Dialog)

     def retranslateUi(self, Dialog):
         Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", 
"Kamera Download", None, QtGui.QApplication.UnicodeUTF8))
         self.gb_Quelle.setTitle(QtGui.QApplication.translate("Dialog", 
"Kopieren von Kamera", None, QtGui.QApplication.UnicodeUTF8))
         self.bb_Quelle.setText(QtGui.QApplication.translate("Dialog", 
"...", None, QtGui.QApplication.UnicodeUTF8))
         self.gb_Ziel.setTitle(QtGui.QApplication.translate("Dialog", 
"in das Grundverzeichnis", None, QtGui.QApplication.UnicodeUTF8))
         self.bb_Ziel.setText(QtGui.QApplication.translate("Dialog", 
"...", None, QtGui.QApplication.UnicodeUTF8))

-- 
Uwe Wilske





Mehr Informationen über die Mailingliste python-de