gpt4 book ai didi

c++ - 如何创建一个行为类似于消息框的 Qt 窗口?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:06:53 25 4
gpt4 key购买 nike

我想创建一个 Qt 弹出窗口,它的行为类似于 Qt 中的消息框。这意味着 GUI 的其余部分必须被阻止,直到该弹出窗口被关闭。这可能是一个 child 问题,但任何人都可以帮我解决这个问题吗?

谢谢...:)

编辑:

我想在该弹出窗口中使用表单、标签、按钮和其他一些小部件类型。

最佳答案

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. When the user closes the dialog, exec() will provide a useful return value. Typically, to get the dialog to close and return the appropriate value, we connect a default button, e.g. "OK", to the accept() slot and a "Cancel" button to the reject() slot. Alternatively you can call the done() slot with Accepted or Rejected.

An alternative is to call setModal(true) or setWindowModality(), then show(). Unlike exec(), show() returns control to the caller immediately. Calling setModal(true) is especially useful for progress dialogs, where the user must have the ability to interact with the dialog, e.g. to cancel a long running operation. 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. (See QProgressDialog.)

关于c++ - 如何创建一个行为类似于消息框的 Qt 窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1284401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com