当您QMessageBox使用详细文本集打开时,它具有显示详细信息按钮.我希望默认情况下显示详细信息,而不是用户必须先单击" 显示详细信息..."按钮.
据我快速浏览源代码可以看出,没有简单的方法可以直接打开详细信息文本,或者确实访问“显示详细信息...”按钮。我能找到的最好方法是:
ActionRole,因为这对应于“显示详细信息...”按钮。click对此手动调用该方法。此操作的代码示例:
#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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2077 次 |
| 最近记录: |