Using lambda expression to connect slots in pyqt

The QPushButton.clicked signal emits an argument that indicates the state of the button. When you connect to your lambda slot, the optional argument you assign idx to is being overwritten by the state of the button. Instead, make your connection as button.clicked.connect(lambda state, x=idx: self.button_pushed(x)) This way the button state is ignored and the correct … Read more

PyQt: Connecting a signal to a slot to start a background operation

It shouldn’t matter whether the connection is made before or after moving the worker object to the other thread. To quote from the Qt docs: Qt::AutoConnection – If the signal is emitted from a different thread than the receiving object, the signal is queued, behaving as Qt::QueuedConnection. Otherwise, the slot is invoked directly, behaving as … Read more

Background thread with QThread in PyQt

I created a little example that shows 3 different and simple ways of dealing with threads. I hope it will help you find the right approach to your problem. import sys import time from PyQt5.QtCore import (QCoreApplication, QObject, QRunnable, QThread, QThreadPool, pyqtSignal) # Subclassing QThread # http://qt-project.org/doc/latest/qthread.html class AThread(QThread): def run(self): count = 0 while … Read more