W
W
w0lkolak2021-11-26 13:30:09
Python
w0lkolak, 2021-11-26 13:30:09

Where does PyQt get False for a function in a qt slot?

There is a button widget. Clicking on which is connected to the function

def func(self,  a=None, b=None):
      print('a =', a)

self.but.clicked.connect(self.anothe_object.func)


I click on the button and get a=False.
If you make connect to lambda: func() then everything works fine and a=None.

What actually happens?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-11-26
@w0lkolak

The solution is simple: you need to mark func with a decorator

@QtCore.pyqtSlot()
def func(self,  a=None, b=None):
      print('a =', a)

Why this happens: Buttons in Qt have two types of clicked signal - one with no arguments, and one with a checked boolean argument. The second is used for buttons that do not release after being pressed. PyQt chooses the signal type based on the slot's arguments. Yours has an argument a, which means the second type of signal is selected and False is passed in, as an indication that the button is released after being pressed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question