Hello,
is it possible to connect signals from a Widget to a slot in a QThread and
ensure that the Widget responds to keypress and mouse events?
I attached my first try, but it doesn't work, the UI blocks until the execution
of the function is finished.
Thanks for your help,
Lukas
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Main(QWidget):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
# Some widgets to check if the Widget responds to keypress events
layout = QVBoxLayout()
btn1 = QPushButton("Push me...", self)
txt1 = QTextEdit(self)
lin1 = QLineEdit(self)
btn2 = QPushButton("Just testing...", self)
layout.addWidget(btn1)
layout.addWidget(txt1)
layout.addWidget(lin1)
layout.addWidget(btn2)
self.setLayout(layout)
self.thread = Thread()
self.thread.start()
self.connect(btn1, SIGNAL("clicked()"), self.thread, SLOT("long()"))
class Thread(QThread):
def __init__(self, parent=None):
super(Thread, self).__init__(parent)
def run(self):
# Short running method
time.sleep(1)
self.long()
self.exec_()
@pyqtSignature("")
def long(self):
print "Is Thread still running?", self.isRunning()
print "starting long running function..."
time.sleep(4)
print "ending long running function..."
if __name__ == "__main__":
app = QApplication([])
main = Main()
main.show()
app.exec_()
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt