Modal QWidget with a non-QWidget parent
-
Hi,
I'd like to ask you some better ideas about how to solve better my problem.
I'm creating a shared library (let's assume a Win32 dll in this post, but I'd like the solution to be platform independent), which exports some methods.
These methods are called by another application, that can be written in whatever technology available, so the "master" application has its own GUI, with its own event loop.
When the master application calls one of the DLL methods, a modal QWidget appears, running in its private QEventLoop. Well, modality is the problem.
Such QWidget has no parent, so setting windowModality has no effect (am I right?).
Until now, the only way that I found to solve my problem was some Win32 code, that simply gets the actual foreground window and disables it before showing the QWidget, and then enables it again after QWidget (and its event loop) gets closed.
@
class ParentWindowLocker
{
#ifdef WIN32
HWND _wnd;
#endifpublic:
explicit ParentWindowLocker() :
#ifdef WIN32
_wnd(GetForegroundWindow())
#endif
{
#ifdef WIN32
if (_wnd != NULL)
EnableWindow(_wnd,FALSE);
#endif
}~ParentWindowLocker()
{
#ifdef WIN32
if (_wnd != NULL)
{
EnableWindow(_wnd,TRUE);
SetForegroundWindow(_wnd);
}
#endif
}
};
@My questions are:
a) is there a better way (portable would be the best one)? I'd like to let QWidget know the handle of its parent, but I haven't figured out how to do it, and I guess there's no way.
b) if there's no other way, there're some better Win32 APIs to solve this problem? Sometimes it seems that SetForegroundWindow has no effect (i.e., the master window is enabled, but gets minimized instead of staying like it was before calling the DLL method).Thanks a lot,
T.