1

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.

andre
  • 7,018
  • 4
  • 43
  • 75
  • 1
    Well, that's what modal dialogs are for, to stop user interaction with the rest of the application. – Some programmer dude Feb 11 '13 at 18:32
  • @JoachimPileborg I have messages arriving in the background that must be executed by the application as they arrive. – andre Feb 11 '13 at 18:34
  • I guess the question would be clearer if I asked how to disable keyboard and mouse input. – andre Feb 11 '13 at 18:41
  • I think that thing you want to achieve is silly. Modal dialogs are made to disable background windows. Why do you want to remain it modeless if you want to block background window either way? I can't understand that. – Blood Feb 11 '13 at 19:08
  • @Blood I have a asynchronous system. Blocking the background application means I would block more than user triggered events. To be clear I want to block user events suck as mouse clicks, but I do not want to block other events like a packet arrival. – andre Feb 11 '13 at 19:26

2 Answers2

3

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.

Amit Tomar
  • 4,800
  • 6
  • 50
  • 83
Bill
  • 14,257
  • 4
  • 43
  • 55
0

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.

phyatt
  • 18,472
  • 5
  • 61
  • 80