gpt4 book ai didi

c++ - 单击按钮后如何防止关闭 QMessageBox

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:24:27 24 4
gpt4 key购买 nike

我在 QMessageBox 上通过 QMessageBox::addButton() 方法添加了 3 个按钮。如果单击按钮,是否可以防止关闭消息框?默认情况下,每个按钮都会关闭窗口,但我不想为一个按钮执行此操作。

编辑:为什么这会被否决?

最佳答案

一种对我有用的有趣方法是完全断开创建的目标按钮的信号,然后重新添加预期的功能。这对每个人都不起作用,特别是如果按钮不是以这种方式创建的和/或您仍想正确关闭对话框。 (可能有一种方法可以将其添加回来和/或使用 QDialog::acceptQDialog::rejectQDialog::done 模拟行为 - 尚未尝试。)

例子:

QMessageBox *msgBox = new QMessageBox(this);
QAbstractButton *doNotCloseButton = msgBox->addButton(tr("This button will not close anything"), QMessageBox::ActionRole);
// Disconnect all events - this will prevent the button from closing the dialog
doNotCloseButton->disconnect();
connect(doNotCloseButton, &QAbstractButton::clicked, this, [=](){ doNotCloseButton->setText("See? Still open!"); });

关于c++ - 单击按钮后如何防止关闭 QMessageBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12230602/

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