阻塞但非模态QDialog? [英] A blocking but non-modal QDialog?

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

问题描述

我有一堆图像,我想在其上执行一些操作。处理每个图像后,我的程序应该弹出一个对话框,提示用户是否要继续下一个图像或中止。在此之前,他们应该有机会对图像或参数进行一些手动更改。无论如何,他们必须访问应用程序的窗口,而调用对话框的方法的执行应该被阻止,直到对话框关闭。

I have a stack of images on which I want to perform some operations. After processing each image, my program should pop up a dialog to prompt the user if they want to proceed with the next image or to abort. Before that, they should have an opportunity to do some manual changes either on the images or on the parameters. Anyway, they must have access to the windows of the applications, while the execution of the method that called the dialog should be blocked until the dialog is closed.

我试图解决这个与一个QMessageBox,但如果我通过exec()打开它,它阻止整个应用程序,如果我使用show(),程序的执行继续,而不等待用户的反应。

I tried to solve this with a QMessageBox, but if I open it via exec(), it blocks the entire application, and if I use show(), the execution of the program goes on without waiting for user's reaction.

有一个方便的方法来阻止调用方法或函数与对话框,但允许用户与其他窗口交互?

Is there a convenient way to block the calling method or function with a dialog but permit the user to interact with other windows?

感谢

推荐答案

您应该将要封锁的方法拆分为两个部分。在第一部分的结尾,您需要显示您的对话框而不阻塞,并将对话框的下一步按钮(例如)连接到必须包含旧方法的第二部分的插槽。此插槽只有在用户按下按钮时才会执行。

You should split your method that you want to block into two parts. In the end of first part you need to show your dialog without blocking and connect "Next" button (for example) of the dialog to the slot that must contains second part of your old method. This slot will be executed only when user presses the button.

这是在Qt中正确的方法。你需要改变你的代码逻辑来实现这一点。

It's the right way to do it in Qt. You need posibly to change your code logic to implement this.

此外,你真的需要第二个对话框吗?您可以将下一步按钮放置到您的主要小部件。您还可以创建另一个模式对话框,其中将包含一些设置和下一步按钮。

Also, do you really need the second dialog? You can place "Next" button to your main widget. You can also create another modal dialog that will contain some settings and "Next" button.

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

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