Qt模态对话框和主要过程 [英] Qt modal dialog and main process

查看:88
本文介绍了Qt模态对话框和主要过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序在主窗口中执行一些过程,我需要一个模态对话框,上面带有一些自定义元素,以显示进度.它还必须阻止用户与主窗口的交互.显示对话框时,主进程应运行. 为此,在qt中哪种方法更好?

I have a program which executes some process in main window and I need a modal dialog with some custom elements to be shown over it to show the progress. It also must block user interaction with main window. Main process should run while dialog is shown. Which way is better (in qt) for this purpose?

推荐答案

实际上,这听起来有点简单(除非我误解了您的问题).

Actually, this sounds kinda easy (unless I misunderstand your question).

QDialog my_progress_dialog( this );
my_progress_dialog.setModal( true );
my_progress_dialog.show();

调用show()而不是exec()将使您进入主事件循环.同时,设置对话框模式会阻止所有用户输入到主窗口.工作完成.

Calling show() not exec() will leave you in the main eventloop. At the same time, setting the dialog modal blocks all user input to the main window. Job done.

您看过QProgressDialog吗?正是出于这个目的.

Have you looked at QProgressDialog? It's there for exactly this purpose.

这篇关于Qt模态对话框和主要过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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