'Qt change modality of a Dialog at run time without hide it for first time and than show
I have a QMainWindow and from that I openend another dialog using dialog->show(); Inside Dialog I have a button say "Button1" and "Button2".
Here, When user press "Button1" than modality of Dialog should change to "Qt::ApplicationModal" and When user press "Button2" than modality of dialog should change to "Qt::NonModal".
I can do this by using "setWindowModality(Qt::ApplicationModal);" inside "Button1" clicked followed by "hide(); and show();" and "setWindowModality(Qt::NonModal);" inside "Button2" clicked followed by "hide(); and show();"
But, if I use above method than QDialog gives a blink affect which is obvious as I am using "hide() and show()" function. This blink affect I do not want.
So, kindly suggest:
- How to change modality of a QDialog opened by show() without using "hide()" and "show()" after changing modality?
- If there is no other way to change modality of a QDiloag at run time followed by "hide" and "show" than Is it possible to reduce the affect of QDialog disappears and then visible again.
I do not want user to have a toggle effect on the QDialog, kindly suggest.
Thanks,
Solution 1:[1]
I've used QDialog but never needed to change the modality at runtime. Qt docs is quite clear and imperative about Qt::WindowModality
This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the widget first, then show() it again.
So it seems sequence instruction hide() and show() is required to change modality at runtime. A trick could be to create another parallel QDialog with the same properties of the original one except for the modality, and make it overlapping the existing. This is not so "linear", but it's a solution sometimes used to "double" objects. In this case you have to remember which of the QDialog you're currently using.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andre |
