0

Basically i want to make a qtabwidget and start every widget in it in a different thread. So far i tried to emit the widget which does not work cause slot does not support Qwidget. I can however start a widget class in the main thread in which i call a thread and that thread calls another class that draws a QWidget. That works, but as soon as i move my mouse to the window called in the thread i get

QApplication: Object event filter cannot be in a different thread. 

So it's probably not the way it should be done

#!/usr/bin/env python

from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtCore import QThread, SIGNAL
import sys
class seconwidget(QtGui.QWidget):

    def showit(self, toshow):
        toshow.show()
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.setGeometry(300,300,400,400)
        self.setWindowTitle("tryit")
        self.show()
class seconddialog(QThread):
    def __init__(self):
       QThread.__init__(self)

    def run(self):
        self.newwid=seconwidget()

class mainwindow(QtGui.QWidget):

    def showit(self, toshow):
        toshow.show()
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.setGeometry(300,300,400,400)
        self.setWindowTitle("try")
        self.show()
        self.show_thread=seconddialog()
        self.show_thread.start()

if __name__=='__main__':
    app=QtGui.QApplication(sys.argv)
    wind=mainwindow()
    app.exec_()

Can it be done and what's the proper way to do it?

  • No, it can't be done - the GUI must only be in the main thread. But anyway, what's your *specific* use-case? This smells a lot like an [XY Problem](http://meta.stackexchange.com/a/66378/174568): – ekhumoro Nov 27 '15 at 22:34
  • I have a tabwidget. In that tabwidget i use some widgets, which need to load informations before i want to show them. So before i show the tabwidget i want to have some kind of loading info and i thought the easiest to update and least error-prone way would be to call a thread in loading info to call the tabwidget and send a signal when its done, hide loading info, show tabwidget. If i can't do that the only way i can see to manage this is to emit from every little bit that will be loaded in a different thread and somehow count all the required signals. – Pathologic Nov 28 '15 at 08:51

0 Answers0