[PyQt] Show QDialog and execute code after
Maurizio Berti
maurizio.berti at gmail.com
Fri Apr 13 15:54:58 BST 2018
A little bit of context/code might help, at least to understand why do you
need to run that code and display the output *after* the dialog is shown,
and why do you need to do that when the dialog is shown. Also, it is not
clear if the code you run takes a lot of time/resources, which might or
might not block the UI.
Anyway, in similar cases (when I need to actually show the dialog and do
something on/with the interface) I prefer to implement the exec_() method
and return the actual exec_() class method at the end.
In this way I don't need to mess around with modality, results and so on,
leaving the behavior almost intact. Also, you can set custom arguments to
your exec_() implementation, which might come handy.
class MyDialog(QtWidgets.QDialog):
...
def exec_(self):
self.show()
data = self.someMethod(someArgument)
...
self.myTextEdit.setPlainText(processedData)
res = QtWidgets.QDialog.exec_(self)
if res:
#you can do something with the result of the exec_()
if res == self.Yes:
self.doSomething()
return res
Obviously, if the code you need to run there requires too many resources,
you might think about using a QObject moved to a new QThread and use custom
signals to update the data.
Regards,
MaurizioB
2018-04-13 13:00 GMT+02:00 Starglider Developer <starglider.dev at gmail.com>:
> Hi,
> I need after the QDialog is show, to run code and display the output to a
> QTextEdit.
> Now I can only run the code with the QDialog with user input -a
> QPushButton-
> If the code runs inside the
> def __init__(self, parent=None):
>
> the QDialog is not shown until it finish the code execution.
>
> I'm using Python 2.7 and PyQt4.
>
> Thank you in advance.
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
--
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180413/093b4ef9/attachment.html>
More information about the PyQt
mailing list