QMessageBox阻止QDialog [英] QMessageBox blocks QDialog

查看:351
本文介绍了QMessageBox阻止QDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道如何制定我的问题...

我有我的应用程序与一个QDialog作为主窗口。
应用程序从远程机器获得不同的值,如温度,湿度等。

对于开发,我添加了一个包含不同小部件的组件框来模拟这些值。例如,如果温度上升超过30°C,我打开一个QMessageBox的请求时间(应用程序不会在远程机器上查询)和当前温度。所以这是更新每个请求周期。



我使用show()方法调出消息框,使我的应用程序在后台运行。现在的问题是:重点是在消息框,我的主窗口/ QDialog中的任何东西都可以被点击,直到消息框不被接受/已经完成。



这是我的问题:在模拟模式下,我想玩弄不同的温度值,我可以通过主窗口中的滑块进行调整。我怎样才能访问这些小部件/让消息框以某种方式不阻塞?



最好的问候,



Matthias

解决方案

您正在经历的是窗口的模态。默认情况下, QMessageBox 是应用程序模式。这意味着输入到所有其他应用程序窗口被阻止。



要改变模式,请使用 setWindowModality(),其值为 Qt :: WindowModality )。在你的情况:

  box-> setWindowModality(Qt :: NonModal); 
box-> show();


I don't really know how to formulate my question this time...

I have my application with a QDialog as a main window. The application is getting different values like temperature, humidity and so on from a remote machine.

For development I added a group box with different widgets to simulate these values. I have different limits for throwing warnings and alarms to the user.

For example if temperature rises over 30°C then I open a QMessageBox with the request time (the application does polling at the remote machine) and the current temperature. So this is updated each request cycle.

I use the show() method to bring up the message box which keeps my application running in background. The problem now is: the focus is at the message box and nothing in my main window/ QDialog can be clicked until the message box is not accepted/ has finished.

And that's my problem: in simulation mode I want to play around with different temperature values which I can adjust by slider in the main window. How can I access these widgets/ make the message box somehow "not-blocking"?

Best regards,

Matthias

解决方案

What you're experiencing is called "modality" of a window. By default, a QMessageBox is "application modal". This means that input to all other application windows is blocked.

To change the modality, use setWindowModality() with a value from Qt::WindowModality just before you call show(). In your case:

box->setWindowModality(Qt::NonModal);
box->show();

这篇关于QMessageBox阻止QDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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