简体   繁体   English

如何创建一个Qt窗口就像一个消息框?

[英]How to create a Qt window behave like a message box?

I want to create a Qt popup window which will behave like a message box in Qt. 我想创建一个Qt弹出窗口,其行为类似于Qt中的消息框。 That means the rest of the GUI must blocked until that popup window is dismissed. 这意味着必须阻止GUI的其余部分,直到该弹出窗口被解除。 This may be a child question, but can anyone pls help me with this ? 这可能是一个孩子的问题,但任何人都可以帮助我吗?

Thanks... :) 谢谢... :)

Edit: 编辑:

I want to use forms, labels, buttons and some other widget types in that popup window. 我想在弹出窗口中使用表单,标签,按钮和一些其他窗口小部件类型。

Modal Dialogs 模态对话框

A modal dialog is a dialog that blocks input to other visible windows in the same application. 模态对话框是一个对话框,用于阻止同一应用程序中其他可见窗口的输入。 Users must finish interacting with the dialog and close it before they can access any other window in the application. 用户必须完成与对话框的交互并关闭它,然后才能访问应用程序中的任何其他窗口。 Dialogs that are used to request a file name from the user or that are used to set application preferences are usually modal. 用于从用户请求文件名或用于设置应用程序首选项的对话框通常是模态的。

The most common way to display a modal dialog is to call its exec() function. 显示模式对话框的最常用方法是调用其exec()函数。 When the user closes the dialog, exec() will provide a useful return value. 当用户关闭对话框时,exec()将提供有用的返回值。 Typically, to get the dialog to close and return the appropriate value, we connect a default button, eg "OK", to the accept() slot and a "Cancel" button to the reject() slot. 通常,要使对话框关闭并返回适当的值,我们将默认按钮(例如“OK”)连接到accept()插槽,将“Cancel”按钮连接到reject()插槽。 Alternatively you can call the done() slot with Accepted or Rejected. 或者,您可以使用Accepted或Rejected调用done()槽。

An alternative is to call setModal(true) or setWindowModality(), then show(). 另一种方法是调用setModal(true)或setWindowModality(),然后调用show()。 Unlike exec(), show() returns control to the caller immediately. 与exec()不同,show()立即将控制权返回给调用者。 Calling setModal(true) is especially useful for progress dialogs, where the user must have the ability to interact with the dialog, eg to cancel a long running operation. 调用setModal(true)对于进度对话框特别有用,其中用户必须能够与对话框交互,例如取消长时间运行的操作。 If you use show() and setModal(true) together to perform a long operation, you must call QApplication::processEvents() periodically during processing to enable the user to interact with the dialog. 如果同时使用show()和setModal(true)执行长操作,则必须在处理期间定期调用QApplication :: processEvents()以使用户能够与对话框进行交互。 (See QProgressDialog.) (见QProgressDialog。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM