I would like to create a QMessageBox::critical
which would automatically adapt its size depending on the size of the content (the message text). How can I do it?
This is the message I would like to display on the QMessageBox
std::wstring tmpStrEx;
QDomNode tmpNodeParent = node.parentNode();
while(!tmpNodeParent.isNull() && tmpNodeParent.nodeName().toStdWString() != L"root"){
std::wstring tmpStrTmp;
tmpStrTmp = L"<"
+ tmpNodeParent.nodeName().toStdWString()
+ L" nm=\""
+ tmpNodeParent.toElement().attribute(QS(_T("nm")), QS(_T("undef")) ).toStdWString()
+ L"> ";
}
QString mex = "Error while reading vector.<br/><br/>Please check in:<br/><br/> " + tmpStrTmp ;
tmpStrTmp
can be something like <vct nm="name"> <vcx nm="xyz">
I tried in these ways to build the QMessageBox:
First a simple:
QMessageBox::critical(this, "Error", mex);
This shows half message without the content in tmpStrTmp like this:
Error while reading vector.
Please check in:
I thought tmpStrTmp
was the problem but if I put only tmpStrTmp
in the QMessageBox, it shows its content. So, I thought it was a problem of space and I tried these two ways:
1.
QMessageBox msgBox;
QSpacerItem* spacer = new QSpacerItem(500, 500, QSizePolicy::Minimum, QSizePolicy::Expanding);
msgBox.setTextFormat(Qt::RichText);
msgBox.setText( mex );
QGridLayout* layout = (QGridLayout*)msgBox.layout();
layout->addItem(spacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox.exec();
2.
QMessageBox *box = new QMessageBox::QMessageBox(QMessageBox::critical, "Error", mex);
QGridLayout *layout = qobject_cast<QGridLayout *>(box->layout());
if (layout) {
QTextEdit *edit = new QTextEdit(mex);
edit->setReadOnly(true);
layout->addWidget(edit, 0, 1);
}
box->exec();
delete box;
but without success...any help? thanks