I want when the user press the button a form will appear after MainWindow is blocked pending form filling
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- QML: Cannot read property 'xxx' of undefin
- How to get the background from multiple images by
- Evil ctypes hack in python
You need to use a QDialog and show it using exec, which will block the rest of the application until it is closed. The return value of
exec
also tells you whether the form was closed without committing changes (i.e. cancelled).Here is a simple demo script that shows how to use a
QDialog
:Ok , so you want to block the parent window until the child window has been closed.
Use the exec_() function , it will block until the child window is not closed
for further info :
launch a PyQT window from a main PyQt window, and get the user input?
Python - make a window appear on top of another, block access to other windows until button clicked
Subclass your QDialog or your QWidget with your form, and then connect it like this in the constructory of your main window. You will want to convert this code from c++ to python:
EDIT: Added link to docs on using
QDialog::exec()
http://qt-project.org/doc/qt-5/qdialog.html#exec
Hope that helps.
You don't need to do anything that the other answers suggest. Using any
exec()
methods is a surefire way to have bugs, since suddenly your gui code can be reentered. Don't do it.All you need to do is to set proper window modality before you show it (that's the important part). So:
If you wish the window to block only some other window, not the entire application:
Note that this code is for PyQt4 only, it won't work with Qt 5 as there, the window functionality belongs in a class separate from QWidget.
This is what you need
must create Widget inherits from Qdialog