[PySide] User defined signals and slots
Boris Pohler
boris at pohlers-web.de
Tue Oct 29 15:47:55 CET 2013
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