Results 1 to 6 of 6

Thread: QDialog and Multithreading within PYQT5

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2013
    Posts
    36
    Thanks
    14
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5

    Default Re: QDialog and Multithreading within PYQT5

    Thanks for you answer. So I can just add a line "QCoreApplication.processEvents()" after the QDialog is initiated (that would be line 34 here)?

    My second question is still puzzeling me: How do I get a list of all labels, buttons and so on for my Ui_Dialog? It dos not have a children/findchildren method.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDialog and Multithreading within PYQT5

    So I can just add a line "QCoreApplication.processEvents()" after the QDialog is initiated (that would be line 34 here)?
    Probably would have no effect there, since nothing has happened yet in your worker thread. I would try it at the end of "postResult()".

    How do I get a list of all labels, buttons and so on for my Ui_Dialog?
    If you created the dialog's .ui file using Qt Designer, then you (or Qt Designer) would have defined a variable for every QWidget in your dialog (QLabel, QLineEdit, etc.). Open the .ui file in Qt Designer and select any widget. At the top of the Property Editor panel (Execute the View->Property Editor menu command if you don't see it), there will be a QObject entry. Under that is the "objectName" property. This is the name assigned to the widget variable. You can change this to anything you want that is more meaningful ("statusLabel" instead of "label_4" for instance). After all, will you remember next week which label "label_4" refers to?

    Since you are adding the ui into your dialog class by composition (i.e. there is a "ui" member variable for the Ui_Dialog class), then you access the label as "self.ui.statusLabel".
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2013
    Posts
    36
    Thanks
    14
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5

    Default Re: QDialog and Multithreading within PYQT5

    First: Thanks for your time. And thanks for the hint with processEvents. That worked! Here I think I was not clear enough in what I wanted to know:
    Quote Originally Posted by d_stranz View Post
    Since you are adding the ui into your dialog class by composition (i.e. there is a "ui" member variable for the Ui_Dialog class), then you access the label as "self.ui.statusLabel".
    I want to get ALL labels of the Ui_Dialog class - something like
    Qt Code:
    1. Ui_Dialog.findChildren(QWidgets.QLabel)
    To copy to clipboard, switch view to plain text mode 
    if I wanted to find all QLabels ... but this only works for the resultWindow method. How does it work on the Ui_Dialog?
    Qt Code:
    1. dir(Ui_Dialog)
    To copy to clipboard, switch view to plain text mode 
    shows no method Children/findChildren.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDialog and Multithreading within PYQT5

    The documentation for QObject::findChildren() says that the first argument should be a QString that names the type (ie. class) of the widgets you want to retrieve.

    In C++, this is implemented using templates, as the documentation shows. I do not know how this is done in python.

    In addition, you are using the name of your class (Ui_Dialog), not the name of the variable that implements that class in your dialog. So at a minimum, your code should look something like this:

    Qt Code:
    1. self.ui.findChildren( QWidgets.QLabel )
    To copy to clipboard, switch view to plain text mode 

    assuming QWidgets.QLabel is the correct syntax for the argument. Perhaps it should be "QWidgets.QLabel" (ie. a quoted string) instead.

    Or maybe you don't need the "ui" variable at all:

    Qt Code:
    1. self.findChildren( QWidgets.QLabel )
    To copy to clipboard, switch view to plain text mode 

    where "self" is your Dialog class instance.
    Last edited by d_stranz; 22nd March 2020 at 15:52.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Multithreading
    By havij000 in forum Newbie
    Replies: 22
    Last Post: 21st August 2013, 13:35
  2. Replies: 1
    Last Post: 26th March 2013, 02:04
  3. Replies: 9
    Last Post: 25th March 2011, 21:22
  4. QDialog.exec() exiting without calling QDialog::accept()
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2011, 11:35
  5. regarding multithreading
    By mohanakrishnan in forum Qt Programming
    Replies: 19
    Last Post: 9th December 2009, 08:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.