Qt应用程序:模拟模态行为(启用/禁用用户输入) [英] Qt Application: Simulating modal behaviour (enable/disable user input)

查看:114
本文介绍了Qt应用程序:模拟模态行为(启用/禁用用户输入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序,启动单独的进程,显示其他对话框。我想实现的功能是模拟这些对话框的模态行为。更具体地说,我需要应用程序在启动对话框时停止处理鼠标和键盘的所有输入,并在关闭时恢复。



这不重要对话框保持在应用程序的顶部,虽然如果你可以建议如何做,而不诉诸总是在顶部的行为,这也将是很好的。



要注意,应用程序是在Windows和Linux下编译的。此外,它不是直接启动对话框的选项。它们在单独的可执行文件中。此外,该应用程序是一个非常复杂的软件,所以禁用单独的窗口小部件不是一个选项,或至少一个不是很可行的。



我发现 lock ()QApplication类中的() unlock()函数。我们目前使用的Qt 4.5,似乎没有那个API。事实上,Qt 4.5 QApplication类似乎不提供对事件循环的访问。



总结:如何禁用/启用Qt应用程序中的用户输入,鼠标和键盘快捷键?

解决方案

事件,请使用 QObject :: installEventFilter() QCoreApplication :: setEventFilter()

如果您的过滤器函数返回 true ,Qt将停止对事件的进一步处理。 p>

为了避免太多的平台转移事件到你的其他应用程序,我会去一个合适的IPC机制。


I am currently working on an application that launches separate processes which display additional dialogs. The feature I am trying to implement is simulating modal behavior of these dialogs. More specifically, I need the application to stop processing all input, both mouse and keyboard, when the dialog is launched, and resume when it's closed.

It is not so important for the dialog to remain on top of the application, although if you can suggest how to do that without resorting to Always-On-Top behavior, that would be nice as well.

To note, the application is compiled under both Windows and Linux. Also, it is not an option to launch the dialogs directly. They are in separate executables. Also the application is a pretty complex piece of software, so disabling widgets individually is not an option, or at least a not very viable one.

I found lock() and unlock() functions in QApplication class in Qt 3.3. We are currently using Qt 4.5, which doesn't seem to have that API. As a matter of fact, Qt 4.5 QApplication class doesn't seem to provide access to the Event Loop either.

To summarize: How do I disable/enable user input in a Qt Application, both mouse and keyboard shortcuts?

解决方案

To get full access to the application wide events, use QObject::installEventFilter() or QCoreApplication::setEventFilter() on your application object.
If your filter function returns true, Qt stops further processing of the event.

To not get too platform specific with the forwarding of the events to your other applications, i'd go for a suitable IPC mechanism.

这篇关于Qt应用程序:模拟模态行为(启用/禁用用户输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆