Created
September 27, 2017 17:08
-
-
Save eyllanesc/b43b4a843fa73854ba9a8911f79f449f to your computer and use it in GitHub Desktop.
Possible solution off https://stackoverflow.com/questions/46406022/how-to-connect-a-signal-to-a-slot-in-a-different-thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5 import QtCore, QtGui, QtWidgets | |
class Ui_MainWindow(object): | |
def setupUi(self, MainWindow): | |
self.keyworddict = {} | |
self.count = {} | |
MainWindow.setObjectName("MainWindow") | |
MainWindow.resize(698, 581) | |
MainWindow.setMinimumSize(QtCore.QSize(698, 581)) | |
MainWindow.setMaximumSize(QtCore.QSize(698, 581)) | |
palette = QtGui.QPalette() | |
brush = QtGui.QBrush(QtGui.QColor(154, 161, 161)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) | |
brush = QtGui.QBrush(QtGui.QColor(206, 206, 206)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) | |
brush = QtGui.QBrush(QtGui.QColor(214, 214, 214)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) | |
brush = QtGui.QBrush(QtGui.QColor(154, 161, 161)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) | |
brush = QtGui.QBrush(QtGui.QColor(206, 206, 206)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) | |
brush = QtGui.QBrush(QtGui.QColor(214, 214, 214)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) | |
brush = QtGui.QBrush(QtGui.QColor(154, 161, 161)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) | |
brush = QtGui.QBrush(QtGui.QColor(214, 214, 214)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) | |
brush = QtGui.QBrush(QtGui.QColor(214, 214, 214)) | |
brush.setStyle(QtCore.Qt.SolidPattern) | |
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) | |
MainWindow.setPalette(palette) | |
self.centralWidget = QtWidgets.QWidget(MainWindow) | |
self.centralWidget.setObjectName("centralWidget") | |
self.comboBox = QtWidgets.QComboBox(self.centralWidget) | |
self.comboBox.setGeometry(QtCore.QRect(20, 60, 371, 31)) | |
font = QtGui.QFont() | |
font.setFamily("Yu Gothic") | |
font.setPointSize(16) | |
self.comboBox.setFont(font) | |
self.comboBox.setAcceptDrops(False) | |
self.comboBox.setObjectName("comboBox") | |
self.comboBox.addItem("") | |
self.comboBox.addItem("") | |
MainWindow.setCentralWidget(self.centralWidget) | |
self.retranslateUi(MainWindow) | |
def retranslateUi(self, MainWindow): | |
_translate = QtCore.QCoreApplication.translate | |
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) | |
self.comboBox.setItemText(0, _translate("MainWindow", "Jackets")) | |
self.comboBox.setItemText(1, _translate("MainWindow", "Shirts")) | |
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): | |
def __init__(self, parent=None): | |
QtWidgets.QMainWindow.__init__(self, parent) | |
self.setupUi(self) | |
self.thread = Threadclass2(self) | |
self.comboBox.currentTextChanged.connect(self.thread.setText) | |
self.thread.start() | |
class Threadclass2(QtCore.QThread): | |
def __init__(self, parent=None): | |
super(Threadclass2, self).__init__(parent) | |
self._text = "" | |
def setText(self, text): | |
self._text = text | |
def run(self): | |
while True: | |
print(self._text) | |
QtCore.QThread.sleep(0.1) | |
if __name__ == "__main__": | |
import sys | |
app = QtWidgets.QApplication(sys.argv) | |
w = MainWindow() | |
w.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment