Pregunta

I have a modeless QDialog box that popup on errors/warning in my Qt application, I want to force the user to only focus on that dialog box and not click anything in the application until they clicked Ok on the dialog box.

I need the dialog box to remain modeless. A solution like hiding the main window or covering it up is not acceptable.

At the moment I'm using setModal(true); to solve my problem. But I think this method might be stopping the main application from executing.

¿Fue útil?

Solución

From the documentation:

If you use show() and setModal(true) together to perform a long operation, you must call QApplication::processEvents() periodically during processing to enable the user to interact with the dialog.

Otros consejos

Instead of using a QDialog box, try using qDebug statements in your code or a log file using qInstallMsgHandler.

You could also show a QTextEdit and post your log/error messages there in real time, too.

http://qt-project.org/doc/qt-4.8/debug.html

http://qt-project.org/doc/qt-4.8/qdebug.html#details

http://qt-project.org/doc/qt-4.8/qtglobal.html#qInstallMsgHandler

http://qt-project.org/doc/qt-4.8/qtextedit.html#details

If you still really want to debug using a QDialog box for errors, in a pseudo modal dialog but not modal dialog, you could try using eventFilters to prevent mouse and keyboard events from arriving at any other window, but it would be tricky to allow the exception to end up only at QDialog, but it is do-able.

You could also go to the one or two widgets that accept mouse and keyboard input, and ignore the input if the a QDialogBox is visible. But both of these ways of showing an error, but limiting input without making it Modal is really hacky, and would probably be error prone.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top