When you open a QMessageBox with detailed text set it has the show details button. I would like the details to be displayed by default, rather than the user having to click on the Show Details... button first.
When you open a QMessageBox with detailed text set it has the show details button. I would like the details to be displayed by default, rather than the user having to click on the Show Details... button first.
This function will expand the details by default and also resize the text box to a bigger size:
#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);
On Qt5 at least:
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();