Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3571
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T19:30:51+00:00 2022-06-02T19:30:51+00:00

python – Create and update QListWidget() with QListWidgetItem via a spawned thread process

  • 0

[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]

  • 0 0 Answers
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8056 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1842 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1924 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.