[PySide] User defined signals and slots

Boris Pohler boris at pohlers-web.de
Tue Oct 29 16:27:42 CET 2013


As the Traceback says your buttons have no signal pushed, so show us,
how you added this signal to your buttons.

Instead you could use a QSignalMapper
http://pysnippet.blogspot.de/2010/06/qsignalmapper-at-your-service.html
or the partial from the python module functools:
http://stackoverflow.com/questions/9966731/pyside-pyqt-simple-way-to-bind-multiple-buttons-that-shares-the-same-function

HTH
Boris

Am Dienstag, den 29.10.2013, 16:02 +0100 schrieb Hedieh Ebrahimi:
> I have tried that, but if I transmit function as parameter with no
> arguments like this :
> 
> self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"),
> self.askforfileBTN)
> 
> 
> then my pushButton doesn´t do anything on click..
> 
> def askforfileBTN(self,myLineEdit):
>          
>         curFileName=myLineEdit.text()
>         (fileName, _selectedFilter) =
> QtGui.QFileDialog.getOpenFileName(self,
> filter="*.txt;;*.*",viewMode="Detail")
>         if fileName!="" and fileName!=curFileName:
>             myLineEdit.setText(fileName)
> 
> 
> 
> Also when i try the new style as this :
>         self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN)
> 
> 
> 
> I get the following error:
> 
> AttributeError: 'PySide.QtGui.QPushButton' object has no attribute
> 'pushed'
> 
> 
> 
> any ideas what i might be doing wrong?
> 
> 
> Thanks
> 
> 
> 
> 
> On 29 October 2013 15:47, Boris Pohler <boris at pohlers-web.de> wrote:
>         When you connect the signal to the slot you call the function
>         self.askforfileBTN(self.ui.X_Vel_lineEdit). You want transmit
>         the
>         function as parameter instead like
>         
>         self.connect(self.ui.X_Vel_pushButton,
>         QtCore.SIGNAL("pushed()"),
>         self.askforfileBTN)
>         
>         btw, you are using the old style for connecting signals and
>         slots, you
>         better use the new style
>         
>         self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN)
>         
>         HTH
>         Boris
>         
>         Am Dienstag, den 29.10.2013, 15:27 +0100 schrieb Hedieh
>         Ebrahimi:
>         > Hi all,
>         >
>         >
>         > In my User Interface, I have many pushButtons. When one of
>         these
>         > pushButtons is clicked, a function is called that will open
>         a
>         > QFileDialog that will let you browse for a file as below:
>         >
>         >  def askforfile(self):
>         >
>         >         curFileName=self.ui.X_Vel_lineEdit.text()
>         >         (fileName, _selectedFilter) =
>         > QtGui.QFileDialog.getOpenFileName(self,
>         > filter="*.txt;;*.*",viewMode="Detail")
>         >
>         >
>         >
>         > As I have so many of these browse buttons, I was thinking to
>         edit the
>         > " askforfile" method so that it would take the QEditLine
>         that is
>         > operating on as an argument.
>         >
>         >
>         > Then I understood that Clicked which is a pushButton
>         predefined thing,
>         > doesn´t accept arguments and I can not have the following
>         line in my
>         > code.
>         >
>         >
>         >
>         self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN(self.ui.X_Vel_lineEdit))
>         >
>         >
>         > as the self.askforfileBTN(self.ui.X_Vel_lineEdit)) has
>         > self.ui.X_Vel_lineEdit as its argument.
>         >
>         >
>         > , so finally I defined the following signal and then i
>         connected it.
>         >
>         > pushed=QtCore.Signal(self.ui.X_Vel_lineEdit)
>         >
>         > self.connect(self.ui.X_Vel_pushButton,
>         QtCore.SIGNAL("pushed()"),
>         > self.askforfileBTN(self.ui.X_Vel_lineEdit))
>         >
>         >
>         > and now what happens is that the the fileDialog opens even
>         before the
>         > main Window opens and before i even click the push button.
>         >
>         >
>         > Any ideas on what I might be doing wrong?
>         >
>         >
>         > Thanks
>         >
>         
>         > _______________________________________________
>         > PySide mailing list
>         > PySide at qt-project.org
>         > http://lists.qt-project.org/mailman/listinfo/pyside
>         
>         
> 
> 





More information about the PySide mailing list