[SOLVED] Problem with QMessageBox
-
I would like to create a
QMessageBox::criticalwhich would automatically adapt its size depending on the size of the content (the message text). I tried but I have some problems...This is the message I would like to display on the QMessageBox
@ std::wstring tmpStrEx;
QDomNode tmpNodeParent = noderemoved;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 ;@tmpStrTmpcan 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
tmpStrTmpwas the problem but if I put onlytmpStrTmpin the QMessageBox, it shows its content. So, I thought it was a problem of space and I tried these two ways:@
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();@@ 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
-
By using this code
@ QString mex = "Error while reading vector.<br/><br/>Please check in:<br/><br/> " + tmpStrTmp ;
QMessageBox::critical(this, "Error", mex);@the QMessageBox looks like this:
https://drive.google.com/a/hydros.ch/file/d/0B7vJt21ZesT0bkJMY2Y2dFFKNTA/edit?usp=sharing
and with this code
@ QString mex = tmpStrTmp ;
QMessageBox::critical(this, "Error", mex);@the QMessageBox looks like this:
https://drive.google.com/a/hydros.ch/file/d/0B7vJt21ZesT0SGIwN3FxM0Q1c2s/edit?usp=sharing
Can you see the photos?
-
you know? I solved the problem....< and > caused the problem, I replaced them with & lt; and & gt; and worked! I think because "mex" contains html tag (<br/>) and so it interpreted all like html....I don't know how to explain it with the right words, but I hope you understood. Thank you Clochydd, I really appreciate your help! Have a nice day? evening? bye