[ad_1]
So I have exhausted everything I’ve found on python threading and multiprocessing and have used a few examples to get a proof of concept working, but although I can insert QListWidgetItem()’s in a QListWidget i need to attach a signal/slot to that inserted item on the list and have it updated (lets say while its downloading a file show progress) on the fly via a different thread continuously connected to the certain row. Is this possible?!
Currently my hacky way of doing it minimally is:
class ThreadClass7(QtCore.QThread):
progress_sig = QtCore.pyqtSignal(str)
# finished = QtCore.pyqtSignal()
def __init__(self, parent = None):
super(ThreadClass7, self).__init__(parent)
def run(self):
self._stopped = False
for i in range(5):
time.sleep(.5)
self.progress_sig.emit(str(i+1))
def stop(self):
self._stopped = True
// not the entire code, but just sections to show the way its setup
class MainWindow(QMainWindow, Ui_baldr_mainwin):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.worker_thread = ThreadClass7(self)
def create_widget(self):
## create widget to insert into QListWidget for live updating
thread = threading.Thread(target=self.worker_thread.start)
thread.daemon = True
thread.start()
thread.join()
def update_gui(self, msg):
print(f'Updating GUI: {msg}')
# Add widget to QListWidget funList
itemN = QtWidgets.QListWidgetItem()
# Create widget
widget = QtWidgets.QWidget()
widgetText = QtWidgets.QLabel(msg)
widgetButton = QtWidgets.QPushButton("Push Me")
widgetLayout = QtWidgets.QHBoxLayout()
widgetLayout.addWidget(widgetText)
widgetLayout.addWidget(widgetButton)
widgetLayout.addStretch()
widgetLayout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
widget.setLayout(widgetLayout)
itemN.setSizeHint(widget.sizeHint())
self.ui_baldr.current_queue.addItem(itemN)
self.ui_baldr.current_queue.setItemWidget(itemN, widget)
But the problem with this code is that per instance it creates when i press a button which calls createwidget() which then creates a thread which starts ThreadClass7 signaling update_gui() to add a widget item to the QListWidget.
I somehow need to be able to create that QListWidgetItem, add to ListWidget and have a spawned thread constantly controlling it and updating its value’s. Let’s say insert a progress bar and have it count from 0-100 over and over. Can this be done in multithreading with these types of widgets?
[ad_2]