[Interest] Multiple windows app modal?
John Weeks
john at wavemetrics.com
Tue Mar 5 02:06:18 CET 2013
I have a need to make a group of windows behave in an app modal fashion, while being mutually non-modal. That is, the GUI in each of this group of windows is still responsive, but nothing should be allow in windows that aren't part of this group.
I'm part of the way there by running a private event loop and event filter. The event filter blocks events for windows that aren't in the group (returns true for those events) and allows them (returns false) if the target window is one of the windows in the group.
But there is (at least) one flaw- other windows can be activated. That is, they appear activated, but since I'm blocking any mouse and key events, they don't do anything.
I'm wondering how Qt achieves the high-quality window modality that they use for a dialog. Or is it just that window modality is something that both Windows and Mac provide as an OS service, but what I want is not?
Thanks to all!
-John
An "IgorWindow" is a class w use to encapsulate the parts of a window that are special to our application.
bool PauseForUserObject::eventFilter(QObject *watched, QEvent *event)
{
Q_UNUSED(watched);
bool result = false; // means "don't block this event"
// This seems fragile. I have gone through the event type definition in qcoreevent.h and I am blocking
// all the events that sound like GUI interaction events.
if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease ||
event->type() == QEvent::MouseMove ||
event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease ||
event->type() == QEvent::Wheel ||
event->type() == QEvent::DragEnter ||
event->type() == QEvent::DragMove ||
event->type() == QEvent::DragLeave ||
event->type() == QEvent::Drop ||
event->type() == QEvent::DragResponse)
{
IgorWindow * watchedWindow = IgorWindowFromQObject(watched);
if (watchedWindow == NULL)
result = true; // block it
else
{
result = !_windowIsRelatedToInterestingWindow(watchedWindow);
}
}
if (event->type() == QEvent::Paint)
result = false; // allow paint events for any window.
if (event->type() == QEvent::ContextMenu ||
event->type() == QEvent::MouseButtonDblClick ||
event->type() == QEvent::InputMethod ||
event->type() == QEvent::TabletMove ||
event->type() == QEvent::TabletPress ||
event->type() == QEvent::TabletRelease ||
event->type() == QEvent::OkRequest ||
event->type() == QEvent::HelpRequest ||
event->type() == QEvent::IconDrag ||
event->type() == QEvent::Shortcut ||
event->type() == QEvent::ShortcutOverride ||
event->type() == QEvent::WhatsThisClicked ||
event->type() == QEvent::EnterWhatsThisMode ||
event->type() == QEvent::LeaveWhatsThisMode ||
event->type() == QEvent::HoverEnter ||
event->type() == QEvent::HoverLeave ||
event->type() == QEvent::HoverMove ||
event->type() == QEvent::NonClientAreaMouseMove ||
event->type() == QEvent::NonClientAreaMouseButtonPress ||
event->type() == QEvent::NonClientAreaMouseButtonRelease ||
event->type() == QEvent::NonClientAreaMouseButtonDblClick ||
event->type() == QEvent::GrabMouse ||
event->type() == QEvent::UngrabMouse ||
event->type() == QEvent::GrabKeyboard ||
event->type() == QEvent::UngrabKeyboard ||
event->type() == QEvent::TouchBegin ||
event->type() == QEvent::TouchUpdate ||
event->type() == QEvent::TouchEnd
)
{
result = true; // block this event
}
return result; // this block EVERYTHING
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130304/7940317f/attachment.html>
More information about the Interest
mailing list