How to make QFileDialog not modal in Qt5?

别来无恙 提交于 2019-12-11 09:55:19

问题


In previous versions of Qt we were able to use following constructor of file dialog:

QFileDialog(QWidget * parent = 0, const char * name = 0, bool modal = FALSE)

So, it looks like it was possible to make non-modal file dialog. But now (in Qt5) we haven't such parameters in constructor. Also QFileDialog ignores setWindowModality(Qt::NonModal); and setModal(false); (I've checked, that if windowModality() == Qt::NonModal && isModal() == false, file dialog window is still modal).

Do you have ideas, how to make my file dialog non-modal?

Details: my file dialog inherited from QFileDialog. It works absolutely as expected. The only thing I need is to make it non-modal, but I can't find solution on SO and on qt-project. Thank you in advance.


回答1:


The "problem" is that you open the file dialog as a modal window by calling QDialog::open() function. According to the Qt docs for QDialog::open():

Shows the dialog as a window modal dialog, returning immediately.

To make the file dialog non modal simply open it with QDialog::show().



来源:https://stackoverflow.com/questions/24279382/how-to-make-qfiledialog-not-modal-in-qt5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!