首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QMessageBox“显示细节”

QMessageBox“显示细节”
EN

Stack Overflow用户
提问于 2016-03-18 11:46:58
回答 2查看 4.6K关注 0票数 12

当您打开具有详细文本设置的QMessageBox时,它有“显示详细信息”按钮。我希望在默认情况下显示详细信息,而不是用户必须单击Show .按钮第一。

EN

回答 2

Stack Overflow用户

发布于 2016-03-18 12:15:31

来源的快速浏览中我可以看出,没有一种简单的方法可以直接打开细节文本,或者访问“显示详细信息.”按钮。我能找到的最好的方法是:

  1. 遍历消息框上的所有按钮。
  2. 提取一个角色ActionRole,因为这对应于“显示详细信息.”按钮。
  3. 对此手动调用click方法。

这方面的代码示例如下:

代码语言:javascript
复制
#include <QAbstractButton>
#include <QApplication>
#include <QMessageBox>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QMessageBox messageBox;
    messageBox.setText("Some text");
    messageBox.setDetailedText("More details go here");

    // Loop through all buttons, looking for one with the "ActionRole" button
    // role. This is the "Show Details..." button.
    QAbstractButton *detailsButton = NULL;

    foreach (QAbstractButton *button, messageBox.buttons()) {
        if (messageBox.buttonRole(button) == QMessageBox::ActionRole) {
            detailsButton = button;
            break;
        }
    }

    // If we have found the details button, then click it to expand the
    // details area.
    if (detailsButton) {
        detailsButton->click();
    }

    // Show the message box.
    messageBox.exec();

    return app.exec();
}
票数 8
EN

Stack Overflow用户

发布于 2021-04-22 09:26:21

至少在Qt5上:

代码语言:javascript
复制
    QMessageBox msgBox;
    msgBox.setText("Some text");
    msgBox.setDetailedText(text);

    // Search the "Show Details..." button
    foreach (QAbstractButton *button, msgBox.buttons())
    {
        if (msgBox.buttonRole(button) == QMessageBox::ActionRole)
        {
            button->click(); // click it to expand the text
            break;
        }
    }

    msgBox.exec();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36083551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档