Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt no button.clicked.connect function?

Tags:

python

pyqt4

I've got PyQt4 with a python 3.4 and there is this strange bug occurring. Whenever I try to call btn.clicked.connect(), Pycharm will throw this error:

Cannot find reference "connect" in "function".

So for example:

btn = QtGui.QPushButton("Quit", self)
btn.clicked.connect(QtCore.QCoreApplication.instance().quit)

will throw this error. How? Do I have missing files?

like image 331
Rok Dolinar Avatar asked Oct 14 '15 17:10

Rok Dolinar


People also ask

How to add action to a button in PyQt?

QPushButton is a simple button in PyQt, when clicked by a user some associated action gets performed. For adding this button into the application, QPushButton class is used. When the button is pressed it should perform some action, in order to add action to a button we will use clicked.connect method.

How to process button click event in PyQt qpushbutton?

where button is pyqt QPushButton widget, function is a name of function. In this code, we make btn_search button bind a click event on_file_search. To process button click event, we should define on_file_search () function. Here is an example: on_file_search () will show a dialog to display a text you have entered in a QLineEdit.

How to create a button in PySide2 using qapplication?

Now, as mentioned in previous examples you must create the QApplication which will run your PySide2 code: Let's create the clickable button, a QPushButton. We pass a python string on the constructor which will label the button: Before we show the button, we must connect it to the say_hello () function that we defined previously.

How to use Qt with Python?

Basically, this Qt feature allows your graphical widgets to communicate with other graphical widgets or your own python code. Our application will create a clickable button which will show Button clicked, Hello! in the python console each time you click it.


1 Answers

According to Events and Signals in PyQt4 - PyQt4 Tutorial - ZetCode:

PyQt4.5 introduced a new style API for working with signals and slots.

QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'),self.onClicked)

This is the old style API.

button.clicked.connect(self.onClicked)

The new style adheres more to the Python standards.

like image 176
ivan_pozdeev Avatar answered Sep 24 '22 23:09

ivan_pozdeev