答案 0 :(得分:3)
据我所知,通过the source快速查看,没有简单的方法可以直接打开详细信息文本,或者确实访问"显示详细信息..."按钮。我能找到的最佳方法是:
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();
}
答案 1 :(得分:0)
此功能将默认扩展细节,并将文本框的大小调整为更大的尺寸:
#include <QTextEdit>
#include <QMessageBox>
#include <QAbstractButton>
void showDetailsInQMessageBox(QMessageBox& messageBox)
{
foreach (QAbstractButton *button, messageBox.buttons())
{
if (messageBox.buttonRole(button) == QMessageBox::ActionRole)
{
button->click();
break;
}
}
QList<QTextEdit*> textBoxes = messageBox.findChildren<QTextEdit*>();
if(textBoxes.size())
textBoxes[0]->setFixedSize(750, 250);
}
... //somewhere else
QMessageBox box;
showDetailsInQMessageBox(box);
答案 2 :(得分:0)
至少在 Qt5 上:
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();